Rebuild a projection
This guide shows you how to rebuild a projection after you change its logic.
-
Make sure the projection overrides
ResetAsync. Without it, the rebuild job fails with DBX023. -
Deploy the new projection code.
-
Queue the rebuild from the CLI:
Terminal window deedbox rebuild cart_summary --provider postgres --connection "$DEEDBOX_CONNECTION" --waitOr from code:
var status = await admin.GetStatusAsync();foreach (var consumer in status.Consumers)Console.WriteLine($"{consumer.Name}: {consumer.Status}, {consumer.Lag} behind");var rebuild = await admin.RebuildAsync("cart_summary");var skip = await admin.SkipAsync("cart_totals", stalledEventId);var job = await admin.GetJobAsync(rebuild);
What happens
Section titled “What happens”- A running app instance takes the job. It calls
ResetAsyncand sets the projection torebuilding, in one transaction. - The background runner replays every event from position 0.
- For an inline projection, appends skip the projection while it rebuilds. When the replay is within one batch of the head, the runner locks the position counter, applies the last events, and sets the projection back to
running. Appends apply it inline again from then on. - For an async projection, the runner sets it back to
runningwhen it reads to the end.
During the rebuild, the read model is empty or partial. The health check reports rebuilding as healthy, so Kubernetes does not restart the app.
If appends arrive faster than the replay, the runner switches over anyway after 20 polls without progress. Appends then wait while it applies the rest.