Watch and Observe

Two streams replace polling: Watch tells the agent when its fleet changed, Observe reports what the fleet looks like.

Waiting without polling

A trigger on fleet_revisions calls pg_notify('robotelos_fleet_revision', '<fleet>:<revision>'). Each coordinator holds one LISTEN connection and wakes the fleets waiting on that revision. A waiter is registered before the database is read, so a change cannot slip between the read and the wait. A safety read every 15 seconds, and plain polling while the listener is down, cover a lost notification.

FleetWatch

A server stream. The agent sends the revision it has; the coordinator answers with a bookmark when something newer exists, and the agent then fetches the snapshot. Where a transport cannot stream, the agent falls back to a long poll.

FleetObserve

A bidirectional stream from the agent. The first message is a hello with an epoch; the agent then sends the full state of the world, followed by only the changes (upsert and delete) and heartbeats. Messages carry a sequence number; a new epoch replaces the previous set. A second stream for the same fleet supersedes the first, which ends with FailedPrecondition. The reports land in the existing status tables, so the console reads them as before. Without a stream the agent sends unary reports.

Measured

On a laptop, with PostgreSQL 17 in Docker (one run each, not a benchmark of a deployment):

BeforeAfter
Database transactions a second, 100 idle fleets5010.6
Database transactions a second, 400 idle fleets2,0010.6
Time for a change to reach waiting fleetsbaselineabout three times faster
Pool readiness reaching the control planea poll intervalmilliseconds

They come from a laptop run with one database container, so read them as a comparison, not as capacity.

Next steps