Transactions and Consistency Basics
Lesson 12Beginner1h 18mAssessment-backed

Transactions and Consistency Basics

Learn how transactions, consistency, idempotency, and eventual consistency protect correctness in production systems.

What you will be able to do

Explain transactions and consistency in practical system design language.
Identify which product flows require strong correctness.
Understand eventual consistency and when it is acceptable.
Use idempotency, outbox, and compensation patterns at a beginner level.
Map consistency-sensitive designs to AWS, GCP, and Azure storage choices.

Consistency is about what users and systems are allowed to believe after data changes. Transactions are one tool for protecting correctness when multiple changes must succeed or fail together.

Why Consistency Matters

Not every piece of data needs immediate consistency. But some flows, such as payment, inventory, account balance, and certificate issuance, can damage trust if they become contradictory.

Consistency spectrum from strong transactions to eventual consistency
Correctness requirements decide whether a flow needs transactions, idempotency, events, or eventual consistency.
FlowConsistency needReason
Payment captureStrong correctnessDo not charge twice or lose confirmed payment.
Inventory checkoutStrong enough to prevent oversellBusiness correctness.
Unread badge countEventual consistency usually okayA short delay is acceptable.
Analytics dashboardEventual consistency okayReporting can lag.
Certificate issuanceStrong enough to prove eligibilityCredential trust and audit.

Transactions in Plain Language

A transaction groups changes so they are committed together or rolled back together. This is useful when partial success would create invalid business state.

Transaction propertyBeginner meaningExample
AtomicityAll changes happen or none happenCreate order and order items together.
ConsistencyRules remain validOrder total matches item totals.
IsolationConcurrent actions do not corrupt each otherTwo checkouts do not reserve the same last item.
DurabilityCommitted data survives failureConfirmed payment receipt remains after crash.

Scenario: Course Certificate Issuance

SkillSkore should issue a certificate only when the user completes required modules and passes assessments. If scoring, eligibility, and certificate issuance are inconsistent, the product loses trust.

StepCorrectness concernDesign response
Assessment submittedAttempt should not be recorded twiceUse idempotency key or unique attempt ID.
Score calculatedScore must match submitted answers and rubricStore immutable answer snapshot and score version.
Module score updatedShould reflect latest valid attempt policyTransactional update or deterministic recalculation.
Certificate issuedShould happen once when eligibleUnique constraint on userId + courseId certificate.
Notification sentShould not block certificate truthAsync event after durable issuance.

Eventual Consistency

Eventual consistency means different parts of the system may temporarily disagree, but they should converge. It is acceptable when the product can tolerate delay and users are not misled.

Eventually consistent dataWhy acceptableGuardrail
Dashboard progress percentageCan update seconds laterShow last updated time if needed.
Email sent statusDelivery depends on providerTrack pending, sent, failed states.
Search indexNew content may appear shortly after writeDo not use search index as source of truth.
Analytics countersBusiness reports can lagDefine freshness expectations.

Design principle

Use strong consistency where contradiction breaks trust. Use eventual consistency where temporary delay is acceptable and the source of truth is clear.

Patterns for Correctness

PatternUse whenExample
Unique constraintPrevent duplicatesOne certificate per user/course.
Idempotency keyClients or workers may retryRetry assessment submission safely.
Outbox patternNeed database write and event publishingStore CertificateIssued event with certificate transaction.
CompensationNeed to undo later stepRefund payment if order fulfillment cannot proceed.
VersioningAvoid stale updatesOnly update profile if version matches.

Cloud Consistency Options

NeedAWSGCPAzure
Relational transactionsRDS/AuroraCloud SQL/SpannerAzure SQL
Conditional writesDynamoDB conditional writesFirestore transactions/SpannerCosmos DB conditional writes/ETags
Event/outbox processingDynamoDB streams/EventBridge/SQSPub/Sub/Cloud TasksEvent Grid/Service Bus
Strong global relational modelAurora Global Database trade-offsSpannerCosmos DB/Azure SQL with region trade-offs
Audit logsCloudTrail/S3Cloud Audit Logs/Cloud StorageAzure Activity Logs/Blob Storage

Beginner Mistakes

  • Treating every field as requiring strong consistency.
  • Using async events for a flow that must be correct before success.
  • Publishing an event before the database transaction commits.
  • Retrying writes without idempotency.
  • Using a cache or search index as the source of truth.

Guided Practice

Practice task

For a ticket booking system, identify three pieces of data that need strong correctness and two that can be eventually consistent.

Sample Answer

DataConsistency decision
Seat reservationStrong correctness to prevent two users booking the same seat.
Payment statusStrong correctness because money and booking trust are involved.
Ticket issuanceStrong enough to issue only once after payment succeeds.
Recommendation widgetsEventually consistent because suggestions can lag.
Analytics dashboardEventually consistent because reporting can refresh later.

Module 3 Wrap-Up

You now have the foundation for storage design: model data from product flows, choose storage based on access patterns, design indexes for reads, and protect correctness with transactions and consistency choices.

Before You Continue

  • You should know which data is source of truth.
  • You should be able to choose SQL or NoSQL with reasoning.
  • You should map query patterns to indexes and read models.
  • You should know when strong consistency matters and when eventual consistency is acceptable.
  • You are ready for Module 4, where data and APIs meet scaling patterns.