Architecture

Like the myna bird with its remarkable ability to listen and recall, MynaDB is built with a layered architecture that captures every signal from your infrastructure. Optimized for high-throughput ingestion and fast analytical queries, this document explains how the components work together to give voice to your machines.

System Overview

                              +------------------+
                              |     Clients      |
                              | (curl, Grafana,  |
                              |  Telegraf, etc.) |
                              +--------+---------+
                                       |
                 +---------------------+---------------------+
                 |                                           |
                 v                                           v
        +--------+--------+                         +--------+--------+
        |   HTTP Server   |                         | Arrow Flight    |
        |   (Port 7000)   |                         |   (Port 7001)   |
        |      Axum       |                         |     Tonic       |
        +--------+--------+                         +--------+--------+
                 |                                           |
       +---------+---------+                                 |
       |                   |                                 |
       v                   v                                 |
  +----+----+        +-----+------+                          |
  |  Write  |        |   Query    |<-------------------------+
  |   API   |        |   API      |
  +----+----+        +-----+------+
       |                   |
       v                   v
  +----+----+        +-----+------+
  |  Line   |        | DataFusion |
  | Protocol|        |   Query    |
  | Parser  |        |   Engine   |
  +----+----+        +-----+------+
       |                   |
       v                   |
  +----+----+              |
  |  Data   |              |
  |  Cache  |<-------------+ (Memtable: query fresh writes)
  | (Memory)|              |
  +----+----+              |
       |                   |
       v                   v
  +----+-------------------+----+
  |       Parquet Storage       |
  |   (Columnar, Compressed)    |
  +-------------+---------------+
                |
                v
  +-------------+---------------+
  |      Metadata Manager       |
  | (Catalogs, Tables, Files)   |
  +-------------+---------------+
                |
                v
        +-------+-------+
        |   Compactor   |
        | (LSM-style)   |
        +---------------+
        

Core Components

HTTP Server (Axum)

The HTTP server handles all REST API requests. Built with Axum, it provides:

Endpoint Method Description
/write/:db POST Write data (Line Protocol)
/query/:db GET/POST Execute SQL queries
/flush POST Flush cache to disk
/compact/:db POST Trigger compaction
/tables/:db GET List tables

Line Protocol Parser

Parses InfluxDB Line Protocol with high performance:

<measurement>,<tag_key>=<tag_value>,... <field_key>=<field_value>,... [timestamp]

# Example:
cpu,host=server01,region=us-west usage=75.5,temp=45i 1609459200000000000

Data Cache & Memtable

In-memory buffer that batches writes for efficiency and provides immediate query visibility:

⚡ Instant Query Visibility (New!)

Writes are immediately queryable via the Memtable - no flush required! The query engine automatically unions data from both the in-memory cache (fresh writes) and Parquet files (flushed data).

Metadata Manager

Memory-based catalog system that tracks all database objects:

📈 Performance Impact

Query planning is 10-100x faster with the Metadata Manager. Zero filesystem scans - all metadata is in memory with periodic JSON persistence.

DataFusion Query Engine

Apache DataFusion provides SQL query capabilities:

Parquet Storage

Data is stored in Apache Parquet format:

Compactor (LSM-style)

Multi-level compaction optimizes storage and query performance:

  Write Path                    Compaction
      |                             |
      v                             |
  +-------+                         |
  |  L0   |  (Recent writes)        |
  +---+---+                         |
      |                             |
      +-----> Merge when 4+ files --+
      |                             |
      v                             |
  +-------+                         |
  |  L1   |  (First compaction)     |
  +---+---+                         |
      |                             |
      +-----> Merge when 4+ files --+
      |                             |
      v                             |
  +-------+                         |
  |  L2   |  (Second compaction)    |
  +---+---+                         |
      |                             |
      ...                           |
      |                             |
      v                             v
  +-------+
  |  L5   |  (Maximum level)
  +-------+
        

Storage Structure

MynaDB uses a hierarchical Catalog.Schema.Table structure:

data/
└── {catalog}/                    # Database name
    ├── {schema}/                 # Service tag value (or "default")
    │   └── {table}/              # Measurement name
    │       └── date=YYYY-MM-DD/  # Date partition
    │           ├── L0_xxx.parquet
    │           ├── L1_xxx.parquet
    │           └── L2_xxx.parquet
    └── _system/
        └── series_stats/         # Cardinality tracking

Schema Strategies

Two strategies for mapping data to the catalog structure:

ServiceAsSchema (Default)

  • Schema = Service tag value
  • Table = Measurement name
  • Best for multi-tenant setups

cpu,service=web → mydb.web.cpu

ServiceAsTable

  • Schema = "default"
  • Table = Service tag value
  • Measurement stored as column

cpu,service=web → mydb.default.web

Arrow Flight

Arrow Flight provides high-performance gRPC streaming:

bash
# Connect with DataFusion CLI
datafusion-cli --host localhost --port 7001

# Run SQL queries
> SELECT * FROM mydb.default.cpu LIMIT 10;

Key Design Decisions

Why Rust?

Why Parquet?

Why DataFusion?

Performance Characteristics

Operation Typical Latency Notes
Write (cached) < 1ms Acknowledged when in memory
Simple query 1-10ms Single table, indexed filter
Aggregation 10-100ms Depends on data size
JOIN query 50-500ms Depends on table sizes
Flush 100-1000ms Depends on cache size
Compaction (L0→L1) 1-10s Runs in background

Next Steps