This document explains how messages flow through Cursus from publication to consumption.
Cursus is a log-centric message broker designed for high-throughput persistence with low-latency real-time delivery. Unlike brokers that treat memory and disk as separate modes, Cursus employs a unified path where every message is destined for a persistent log, while simultaneously being dispatched to active consumers.
When a message is published, it is immediately handed off to the DiskHandler for the target partition.
writeCh and flushed to disk in batches (default 500 messages or 100ms) to maximize I/O efficiency.Simultaneously, the message is enqueued into the partition’s in-memory channel.
run goroutine for each partition fans out messages to registered Consumer Groups.All communication uses a TCP-based length-prefixed protocol:
uint32 indicating the payload size.Cursus implements an optional deduplication mechanism in TopicManager:
dedupMap (sync.Map) tracks message IDs (FNV-1a hash of the payload).CleanupInterval (default 30 mins) are rejected.Messages are routed to partitions within a topic based on:
Key is provided, hash(Key) % PartitionCount ensures ordering for related messages.SUBSCRIBE)Used by Consumer Groups for real-time processing:
run loop reads from the internal buffer.MsgCh of the assigned consumer in each group.PartitionID % ConsumerCount within a group.CONSUME)Used for batch processing or catching up:
CONSUME command triggers a direct read from disk segments via DiskHandler.| Feature | Mechanism | Benefit |
|---|---|---|
| Write Performance | Asynchronous Batching & fsync |
High throughput with durability guarantees. |
| Read Latency | In-memory bypass for active subs | Sub-millisecond delivery for real-time apps. |
| Scalability | Partition-level concurrency | Parallel processing across CPU cores. |
| Reliability | Immutable Segmented Logs | Safe recovery and historical auditability. |
| Pattern | Command | Data Source | Delivery Mode | Use Case |
|---|---|---|---|---|
| Real-time Push | SUBSCRIBE |
In-memory Buffer | Streaming | Stream processing, real-time alerts. |
| Historical Pull | CONSUME |
Disk Segments | Polling | Batch jobs, data analysis, specific offset lookup. |
| Log Streaming | CONSUME |
Disk Segments | Streaming | Catching up from offset and continuing to listen. |
CONSUMECursus supports two modes when reading from the persistent log: