Event-driven read models can be rebuilt safely using a hybrid approach combining PostgreSQL advisory locks with persistent status tracking. Inline projections use shared locks for concurrent processing, while async rebuilds acquire exclusive locks to prevent conflicts. Advisory locks handle fast-path coordination and prevent races during transitions, while status columns provide crash recovery and persist across connection failures. This design enables zero-downtime rebuilds, handles multiple processor instances, and maintains consistency without external infrastructure.
Table of contents
Add new vs update existing.In place update, blue/green rebuild and backfilling dataConcurrency issues while (re)building read modelsDistributed Locking and PostgreSQL advisory locksWhy advisory locks alone aren’t enoughThe hybrid-locking approachThe scenarios walkthroughTLDRSort: