Skip to content

Lecture 04. Concurrency, idempotency and Saga workflows ​

Week 7 · Syllabus and preparation from the course outline; no study date or personal lecture notes have been recorded.

Business scenario ​

Only one meal remains. Concurrent customers submit orders, payment requests time out, and events can be delivered more than once.

Topics to cover in this class ​

  1. Concurrent updates, atomic SQL statements, transactions and unique constraints
  2. Idempotency keys, deduplication records and key/payload conflict semantics
  3. Saga orchestration versus choreography and compensating business operations
  4. Inventory reservation, payment simulation, cancellation and retry behavior
  5. Durable state transitions, the outbox/reconciliation problem and observability

Learning objectives ​

  • Demonstrate no overselling under concurrent requests.
  • Prevent duplicate simulated payments despite retries/redelivery.
  • Recover failed workflows with compensation or explicit reconciliation.

Live demonstration checklist ​

  • Run 20 concurrent reservation requests for stock=1, verify at most one success.
  • Force a payment failure and inspect compensated inventory + terminal order state.

Preparation and optional written reflection (ungraded) ​

Reading focus: Read a Saga article; compare compensation with a real database rollback. Optional individual reflection: Why can a local SQL transaction not atomically cover the database of two independent services?

Study materials: official docs, websites and YouTube ​

Built with VitePress · Notes © 2026 [Your Name]