Skip to content

Overview ​

A PicoMQ deployment has three components. Nodes serve clients and hold only caches. An object store holds the data objects. A SQL database holds the metadata log that coordinates the nodes. The write-ahead log lives in either the object store or the SQL database.

ComponentHoldsOptions
NodeCachespico serve process, or a background worker inside Postgres
Object storeData objects, WAL by defaultS3 and compatible stores, local filesystem
SQL databaseMetadata log, optionally the WALPostgres, SQLite for a single node

Anatomy of a node ​

Each node runs the same stack. An HTTP listener speaks the Pico protocol or Durable Streams, a Kafka listener serves Kafka clients, and an admin listener serves the admin API and the console. Behind them:

  • The ownership router decides whether this node serves a partition or redirects, see Ownership and routing.
  • The topic layer maps names to topics, partitions, and logs, see Topics and streams, and the group coordinator runs consumer groups.
  • The s3stream engine moves records to and from storage.
pico nodeprotocol listenerPico, Durable Streams, Kafkaadmin listenerAPI, consoleownership routerserve here or 307topics and groupspartitions, logs, offsetss3stream engineWAL, objects, cachesSQL databasecommand log, lease, optional WALobject storagedata objects, WAL by defaultrecordsmetadata commandsowner

The engine is the only writer of record data. It appends to a write-ahead log for durability, batches records into larger data objects in the background, and serves reads from caches when it can.

The metadata log ​

All cluster state changes are commands, such as registering a node, opening a stream, committing an object, or fencing a dead node. The full list is in Metadata. A node proposes a command to the SQL database, where an ordered log table assigns it a position. Every node tails that table and applies each command to an in-memory state, so all nodes converge on the same view without talking to each other.

node 1propose + tailnode 2propose + tailcommand log1718192021stateappliedindex 21proposetail + applyapply

The database provides the ordering, which is the property a consensus protocol would otherwise supply. Applying a command is deterministic, so replaying the log always produces the same state. Every 1024 applied commands a node writes a snapshot row and the log below it can be truncated, which keeps replay on startup short. The position of the last applied command is the applied index seen in the admin API.

The applied state answers every routing and placement question: which node owns a stream, which objects exist, which transfers are in flight. Nodes read it from an immutable in-memory view, never from SQL directly, so reads cost nothing and a slow database only delays new commands.

Request routing ​

Any node accepts any request. A request for a partition owned elsewhere gets a 307 redirect to its owner over HTTP, or NOT_LEADER_OR_FOLLOWER over Kafka. Fencing backs this up, so a stale view can cost a hop but never split a stream. The rules are in Ownership and routing.

Background work ​

A few loops run outside the request path. Some run on every node, the rest only on the node holding the SQL lease. None of them is a special role: whichever node holds the lease does that work, and losing it moves the work elsewhere.

LoopRuns onDoes
TailerEvery nodeApplies the metadata log and publishes views
HeartbeatEvery nodeKeeps the node live, and stops it once it is fenced
Transfer watcherEvery nodeHands off or takes over streams in a transfer
Deleted cleanupEvery nodeDestroys owned streams whose topic was deleted
Compaction checkEvery nodeStarts compaction for streams with too many objects
SnapshotWhichever node crosses the intervalWrites the next snapshot
FailoverLease holderFences silent nodes and moves their streams, see Failover
Object expiry and cleanerLease holderReclaims abandoned uploads and deletes destroyed objects, see Garbage collection
TTL sweepLease holderDeletes topics whose TTL lapsed
Token expiryLease holderRemoves expired tokens