# Checkpoints follow the promised commit

Principle `checkpoints-follow-commits`. Persist state and progress together when one store can transact both.

Also searched as: checkpoint, acknowledgement boundary, state and offset atomicity.

A consumer position and its materialized state must agree. Acknowledge processing only after the promised processing completes.

> allowing a single stateful transaction to atomically update both the state and input offsets.

Source: [Q13](/bibliography#q13); [B5](/bibliography#b5-building-event-driven-microservices).

## Failure it prevents

Progress advances without its state, or state commits while replay still reapplies the event.

## Our Effect 4.0.5 reading

SqlClient.withTransaction covers its database boundary. Stream.runForEach expresses handling, not broker acknowledgement or a transaction with a remote provider.

Source: `packages/effect/src/sql/SqlClient.ts`, `packages/effect/src/Stream.ts`.

## How to check

Crash before and after state commit and acknowledgement. Redeliver and compare state with the expected checkpoint. This is our proposed verification, not a quoted procedure.

Continue with [Retry needs idempotent effects](/principles/retry-needs-idempotency), [Dead letters need a return path](/principles/dead-letters-need-a-return-path).

Connect this to [the existing rat-stack guidance](https://ratstack.sh/lore/concurrent-work-needs-an-owner).

Use [the durability skill](/skills/durability) for the full review. Return to [the durability index](/principles/durability).

## Skills
- [Durability starts with a recovery record](/principles/durability)

## Sources
- Bellemare, Adam. *Building Event-Driven Microservices: Leveraging Organizational Data at Scale*. O’Reilly, 2020. [Link](https://www.oreilly.com/library/view/building-event-driven-microservices/9781492057888/). ([b5-building-event-driven-microservices](/bibliography#b5-building-event-driven-microservices))

## References
- [Effect contributors. Effect 4.0.5. sql/SqlClient.ts](https://github.com/Effect-TS/effect/blob/7f524e25cfb49a71ac39b0f44278d08d40dda5de/packages/effect/src/sql/SqlClient.ts). Pinned source for our Effect mapping, not a claim from the book.
- [Effect contributors. Effect 4.0.5. Stream.ts](https://github.com/Effect-TS/effect/blob/7f524e25cfb49a71ac39b0f44278d08d40dda5de/packages/effect/src/Stream.ts). Pinned source for our Effect mapping, not a claim from the book.
