Functional:
Non-Functional:
Transactions Per Second (TPS): Start from a few thousand, scaling to hundreds of thousands or millions TPS.
Data Storage: Scale from terabytes to petabytes.
Concurrent Users: Tens of thousands to hundreds of thousands.
Data Model: Primarily structured, relational data.
Read/Write Ratio: Mixed, e.g., 60% reads, 40% writes.
Average Transaction Size: Small, typical OLTP (e.g., a few KBs).
Data Growth: Assume significant data growth over time, requiring elastic scaling of storage.
connect(host, port, user, password, database_name): Establishes a connection.disconnect(): Closes a connection.beginTransaction(): Starts a new transaction.commit(): Commits the current transaction.rollback(): Aborts the current transaction.executeQuery(sql_statement, parameters): Executes a DML (SELECT, INSERT, UPDATE, DELETE) or DDL statement. Returns result sets for SELECTs, affected row counts for others.prepareStatement(sql_template): Creates a prepared statement.executePrepared(statement_handle, parameters): Executes a prepared statement.getTableSchema(table_name)listTables()Data Model: Relational model (tables, rows, columns).
Metadata Storage: A separate, highly available key-value store (e.g., ZooKeeper/etcd) will store the shard metadata:
+-----------------+ +----------------------+ +---------------------+ +---------------------+ | Client |<--->| Load Balancer / |<--->| Gateway / Router |<--->| Coordination | | (App + Driver) | | Connection Pool | | (SQL Parser, | | Service (ZK/etcd) | +-----------------+ +----------------------+ | Query Planner, | | (Metadata, Leader | | Txn Coordinator) | | Discovery) | +---------------------+ +---------------------+ | ^ (Shard Info, Leader Addr) | (Query to specific Shard Leader) | +----------------------|----------------------+ | | | +-------------------+ +-------------------+ +-------------------+ | Shard 1 (Raft Grp)| | Shard 2 (Raft Grp)| | Shard N (Raft Grp)| | - Leader | | - Leader | | - Leader | | - Follower(s) | | - Follower(s) | | - Follower(s) | | (Data + WAL) | | (Data + WAL) | | (Data + WAL) | +-------------------+ +-------------------+ +-------------------+
Client: Applications with a database driver.
Load Balancer/Connection Pool: Distributes client connections to Gateways.
Single-Shard Write:
Transaction Coordinator (within Gateway):
GTID -> TransactionState (participants, status, anchor_shard_id).Shard (Raft Group):
Strong Consistency vs. Availability/Latency: Chose strong consistency (linearizability) using Raft and a 2PC-like distributed transaction protocol. This can increase latency and reduce availability during network partitions compared to eventually consistent systems (CAP theorem: aiming for CP).
Raft for Shard Replication: Provides strong consistency and fault tolerance within a shard. Simpler than Paxos to understand and implement generally.
ZooKeeper for Coordination: Mature, reliable for metadata, leader discovery. Offloads these tasks from the database core. Alternative: etcd.
Hash Partitioning: Good for even data distribution and point lookups. Less ideal for range queries unless combined with other strategies or specific indexing.
Anchor Shard for Distributed Tx Commit: Avoids ZK becoming a bottleneck for every transaction commit, leveraging the data shards' Raft logs for high throughput.
SQL Interface: Wider adoption and existing ecosystem, but more complex to implement in a distributed manner than NoSQL interfaces.
Coordination Service (ZK) Failure: If ZK cluster goes down, new connections can't find shard leaders, metadata changes are impossible. Mitigate: Robust ZK deployment (e.g., 5 nodes across AZs).
Shard Leader Failure: Raft handles leader re-election within the shard. Brief unavailability during election.
Multiple Node Failures in a Shard: If > (N-1)/2 nodes fail in a Raft group, shard becomes unavailable for writes (loses majority). Mitigate: Deploy replicas across AZs, aim for 3 or 5 replicas.
Hot Shards: Uneven data access patterns can overload a specific shard leader. Mitigate: Good partition key choice, adaptive re-sharding, read replicas (if consistency allows relaxed reads for some queries).
Distributed Transaction Latency: Multi-round protocol inherently adds latency. Minimize by co-locating frequently accessed data.
Anchor Shard Bottleneck (for commits): While distributed, if many distributed transactions involve the same potential anchor shards, those can become write-limited.
Cross-Shard Scans/Joins: Can be very expensive, requiring scatter-gather operations.
Distributed Query Optimizer: Enhance the query planner to better optimize queries that span multiple shards (e.g., pushdowns, smarter join strategies).
Global Secondary Indexes: Implement efficient global secondary indexes for queries on non-partition key columns. This is complex, often requiring separate indexing structures and coordination.
Online Schema Changes (Zero-Downtime): Support for ALTER TABLE without locking tables for extended periods or requiring downtime. Often involves shadow tables or phased rollouts.
Cross-Region Replication (Asynchronous): For disaster recovery, implement asynchronous replication of committed data to a different geographical region.
Tunable Consistency Levels: Allow applications to choose relaxed consistency levels (e.g., eventual consistency for reads on certain data) for better performance/availability where strong consistency isn't strictly needed.
Automated Re-sharding/Elasticity: More dynamic and automated re-sharding based on load or data size to improve load balancing and elasticity.
Time Travel Queries / Point-in-Time Recovery (PITR): Leverage MVCC and transaction logs to allow querying data as of a past timestamp and to restore the database to a specific point in time.
Enhanced Security Features: Row-level security, more granular access controls, integration with external KMS.
Columnar Storage Option: For workloads that might benefit from analytical queries on OLTP data (HTAP), explore options for columnar representations or integration.