Define what APIs are expected from the system...
Producers — publish messages to topics/queues.
Brokers — cluster of servers responsible for storing and serving messages (log-based storage).
Metadata/Coordination service — leader election, cluster membership, topic metadata (can be consensus-based: Raft/ZooKeeper/etcd).
Consumers — pull or receive messages; support consumer groups (competing consumers).
Coordinator/Controller — manages partitions, rebalances consumers, enforces quotas, controller leader.
Storage layer — append-only log files per partition with segmenting, compaction, retention policies.
Replicator — intra-cluster replication (sync/async) for high availability.
Delivery & offset manager — track per-consumer offsets/ACKs.
Admin API & Management UI — create topics, set retention, view status.
Observability stack — metrics, tracing, logging, alerting.
Clients SDKs — for major languages, supporting batching, compression, retries, transactions.
Responsibilities:
Brokers are the heart of the system. Each broker stores partitions, handles replication, and serves consumers.
Responsibilities:
Consumers read messages from brokers and acknowledge progress.
Responsibilities:
Purpose: Maintain cluster state and enable consistent partition leadership.
Responsibilities:
Typical Implementations:
Data Stored:
Purpose: Efficiently persist messages with durability and fast access.
Design:
Responsibilities:
Database primarily needs to store:
Schema:
"Topics": {
"topic_id": "UUID",
"name": "VARCHAR",
"partitions": "INT",
"replication_factor": "INT",
"retention_ms": "BIGINT",
"created_at": "TIMESTAMP"
},
"Partitions": {
"partition_id": "UUID",
"topic_id": "UUID",
"partition_index": "INT",
"leader_broker_id": "UUID",
"replicas": "ARRAY[UUID]",
"created_at": "TIMESTAMP"
},
"Brokers": {
"broker_id": "UUID",
"host": "VARCHAR",
"port": "INT",
"status": "ENUM('ACTIVE','DOWN')",
"last_heartbeat": "TIMESTAMP"
},
"ConsumerGroups": {
"consumer_group_id": "UUID",
"name": "VARCHAR",
"created_at": "TIMESTAMP"
},
"Consumers": {
"consumer_id": "UUID",
"consumer_group_id": "UUID",
"host": "VARCHAR",
"status": "ENUM('ACTIVE','INACTIVE')",
"last_heartbeat": "TIMESTAMP"
},
"Offsets": {
"offset_id": "UUID",
"consumer_group_id": "UUID",
"topic_id": "UUID",
"partition_id": "UUID",
"offset": "BIGINT",
"updated_at": "TIMESTAMP"
},
"Messages": {
"message_id": "UUID",
"topic_id": "UUID",
"partition_id": "UUID",
"key": "VARCHAR",
"payload": "BLOB/JSON",
"created_at": "TIMESTAMP",
"delivered": "BOOLEAN"
},
Messages (the actual payloads) - store in append-only log (custom file storage) or distributed commit log (Cassandra).
Metadata - store in relational DB (PostgreSQL, MySQL) or Key-Value store (etcd, Consul, ZooKeeper).
Offsets / Consumer Tracking - store in Key-Value store (Redis).
Monitoring & Logs - Time-series DB (Prometheus, InfluxDB).