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:
- High-performance async request handling
- Connection pooling and keep-alive
- Graceful shutdown support
- Tower middleware integration
| 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
- Measurement - The table name (e.g., "cpu", "memory")
- Tags - Indexed string key-value pairs for filtering
- Fields - Numeric or string values (the actual metrics)
- Timestamp - Nanosecond Unix timestamp (optional, defaults to now)
Data Cache & Memtable
In-memory buffer that batches writes for efficiency and provides immediate query visibility:
- Buffers incoming data in memory as Arrow RecordBatches
- Organizes by database, schema, table, and date partition
- Background flush every 60 seconds (configurable)
- Manual flush via
/flushendpoint - Memtable: Query engine reads from cache directly for fresh writes
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:
- Catalogs: Database-level containers
- Schemas: Namespace within catalogs (e.g., service groupings)
- Tables: Measurement/metric tables with statistics
- Partitions: Date-based partitions with file counts
- Files: Individual Parquet files with row counts and timestamps
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:
- Full SQL support (SELECT, JOIN, GROUP BY, window functions, CTEs)
- Predicate pushdown to Parquet files
- Parallel query execution
- Memory-efficient streaming
- Columnar processing with Apache Arrow
Parquet Storage
Data is stored in Apache Parquet format:
- Columnar layout - Efficient for analytical queries
- Compression - Up to 90% storage reduction
- Predicate pushdown - Filter at read time
- Schema evolution - Add columns without rewriting
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)
+-------+
- L0 - Recent writes, many small files
- L1-L5 - Progressively larger, merged files
- Compaction triggered when 4+ files at a level
- Parallel compaction for performance
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:
- Columnar data transfer without serialization overhead
- Compatible with DataFusion CLI and Arrow clients
- Streaming results for large datasets
- Runs on port 7001 by default
# 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?
- Memory safety - No null pointer errors or data races
- Zero-cost abstractions - High-level code, C-like performance
- Async/await - Efficient handling of thousands of connections
- Strong type system - Catches errors at compile time
Why Parquet?
- Columnar format - Only read columns you need
- Compression - Snappy, ZSTD, LZ4 support
- Predicate pushdown - Filter before reading
- Ecosystem - Works with Spark, Pandas, Arrow
Why DataFusion?
- Full SQL - No custom query language to learn
- Extensible - Custom functions and optimizations
- Arrow native - Zero-copy data processing
- Active community - Part of Apache Arrow project
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 |