teluzia.Cloud Engineer · Day 144
CHAPTER 21 · CLOUD SYSTEM DESIGN

Database selection and consistency trade-offs

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Database selection is today's starting point. An order needs customers, line items and a transaction updating inventory; relational constraints fit that shape. A session lookup by token may fit key-value storage without requiring joins. You will connect this with consistency and transactions and partition trade-offs. The lesson's artifact brings these decisions together: Compare an order system and activity feed using access patterns, transaction boundaries and acceptable stale reads; write a decision record.

Think of it this way

Database choice resembles choosing a filing system: how records are found and updated together matters more than the number of features.

TOPIC 01 / 03Step by step

Database selection

Choose storage from access patterns, integrity requirements and operations needs. Relational schemas support joins and constraints; key-value designs favor known keys and require deliberate indexing. An order needs customers, line items and a transaction updating inventory; relational constraints fit that shape. A session lookup by token may fit key-value storage without requiring joins.

WORKED EXAMPLE
An order needs customers, line items and a transaction updating inventory; relational constraints fit that shape. A session lookup by token may fit key-value storage without requiring joins.

An access pattern describes how data is read or changed; an index supports a selected lookup; a constraint enforces a data rule. Imagine a reporting requirement adds frequent queries by customer and date to a store designed only for order-ID lookup. The original choice may require secondary indexes, denormalization or a separate read model. List required queries, update frequency and integrity conditions before comparing database categories. Include operational skills and backup/restore behavior, because the team must keep the chosen store reliable. A relational design can simplify coordinated invariants and flexible queries, while a key-oriented design can fit predictable access with different scaling behavior. There is no feature-count winner. Test the important query and write paths using representative data shapes and identify the requirement that would justify revisiting the choice.

Why this matters

A session lookup by token may fit key-value storage without requiring joins.

A common trap

The database with the most features always best fits every workload.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Database selection

Choose storage from access patterns, integrity requirements and operations needs. Relational schemas support joins and constraints; key-value designs favor known keys and require deliberate indexing. An order needs customers, line items and a transaction updating inventory; relational constraints fit that shape. A session lookup by token may fit key-value storage without requiring joins.

WORKED EXAMPLE
An order needs customers, line items and a transaction updating inventory; relational constraints fit that shape. A session lookup by token may fit key-value storage without requiring joins.

An access pattern describes how data is read or changed; an index supports a selected lookup; a constraint enforces a data rule. Imagine a reporting requirement adds frequent queries by customer and date to a store designed only for order-ID lookup. The original choice may require secondary indexes, denormalization or a separate read model. List required queries, update frequency and integrity conditions before comparing database categories. Include operational skills and backup/restore behavior, because the team must keep the chosen store reliable. A relational design can simplify coordinated invariants and flexible queries, while a key-oriented design can fit predictable access with different scaling behavior. There is no feature-count winner. Test the important query and write paths using representative data shapes and identify the requirement that would justify revisiting the choice.

Why this matters

A session lookup by token may fit key-value storage without requiring joins.

A common trap

The database with the most features always best fits every workload.

Consistency

Strong and eventual consistency describe visibility guarantees under defined conditions. Choose per operation where possible; stale catalog reads and stale payment records have different consequences. A catalog update may tolerate a brief stale read, while a payment confirmation must obey the chosen correctness contract. State the operation's guarantee instead of labeling the whole application 'eventual.'

WORKED EXAMPLE
A catalog update may tolerate a brief stale read, while a payment confirmation must obey the chosen correctness contract. State the operation's guarantee instead of labeling the whole application 'eventual.'

A stale read sees an older state; read-your-writes ensures a client sees its own completed write under the supported contract; strong consistency supplies defined immediate visibility guarantees. Imagine a user updates a shipping address and immediately views confirmation. A stale view can confuse the user even if eventual convergence is acceptable elsewhere. Specify the guarantee required for that operation and where the read is served. A later analytics report may tolerate delayed visibility and benefit from a separate replica. Do not infer every distributed store has identical guarantees across operations or regions. Stronger coordination can affect latency and availability under failure, while weaker visibility moves complexity into the application and user experience. Evaluate the business consequence of an old value, then choose and test the specific supported read behavior.

Why this matters

State the operation's guarantee instead of labeling the whole application 'eventual.'

A common trap

All reads in all products tolerate the same amount of staleness.

Transactions and partition trade-offs

Transactions protect coordinated changes within supported boundaries. During a partition, availability and consistency choices become explicit; explain failure behavior instead of treating CAP as a product ranking. A network partition forces decisions about serving requests without coordination. A cross-service payment workflow may need compensating actions because a local database transaction does not automatically cover another service.

WORKED EXAMPLE
A network partition forces decisions about serving requests without coordination. A cross-service payment workflow may need compensating actions because a local database transaction does not automatically cover another service.

Atomicity means a transaction completes as one unit within its supported boundary; a partition interrupts communication; compensation reverses or offsets a completed step when a larger workflow fails. Imagine inventory is reserved successfully but a separate payment operation fails. A local transaction cannot automatically undo an action in another service. Design a state machine for reservation, payment and release, with retries and durable progress records. Decide whether a partition causes the workflow to wait, reject new work or accept an explicitly limited operation. The familiar consistency/availability discussion must specify the failure condition and user contract. Cross-service coordination can provide stronger guarantees but adds dependency and complexity; compensation permits asynchronous progress while requiring careful handling of partial success and failed compensation itself.

Why this matters

A cross-service payment workflow may need compensating actions because a local database transaction does not automatically cover another service.

A common trap

A transaction automatically spans any two unrelated databases.

KEEP THESE WITH YOU

Today’s takeaways

Database selection: Choose storage from access patterns, integrity requirements and operations needs.

Consistency: Strong and eventual consistency describe visibility guarantees under defined conditions.

Transactions and partition trade-offs: Transactions protect coordinated changes within supported boundaries.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed