teluzia.Cloud Engineer · Day 61
CHAPTER 09 · STORAGE AND DATABASES

DynamoDB CRUD and ElastiCache concepts

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

What you’re learning today

Practice DynamoDB item operations and compare durable data with a cache. DynamoDB organizes access around keys and query patterns; ElastiCache speeds selected operations but requires an explicit staleness and failure policy. Your small sandbox table uses one string key and is deleted after a precise CRUD verification. A DynamoDB table has a partition key and optionally a sort key. The complete key identifies an item. GetItem uses that key; Query retrieves a key-defined collection, while Scan examines a broader table and can become costly. Design keys from required access patterns rather than copying a relational schema blindly. PutItem writes an item and can replace an existing one at the same key. UpdateItem changes selected attributes and supports conditional expressions. DeleteItem removes by key. Strongly consistent reads are supported for eligible table/local-index reads, while global secondary indexes use eventually consistent reads; consistency affects observations after writes.

Think of it this way

DynamoDB is the authoritative keyed ledger; a cache is a fast note beside the ledger that may need refreshing.

TOPIC 01 / 03Step by step

Keys and access patterns

A DynamoDB table has a partition key and optionally a sort key. The complete key identifies an item. GetItem uses that key; Query retrieves a key-defined collection, while Scan examines a broader table and can become costly. Design keys from required access patterns rather than copying a relational schema blindly. A services table with string partition key service_id can fetch {"service_id":{"S":"api"}} directly; searching by another arbitrary attribute without an index is not the same efficient key lookup. Access-pattern design makes request cost and performance predictable and prevents a small learning table’s convenient full scan from becoming a poor default in a larger operational automation tool. Assuming every attribute is an efficient query key ignores index design; identify the partition/sort key or suitable index before promising fast arbitrary lookups across all items.

WORKED EXAMPLE
A services table with string partition key service_id can fetch {"service_id":{"S":"api"}} directly; searching by another arbitrary attribute without an index is not the same efficient key lookup.
Why this matters

Access-pattern design makes request cost and performance predictable and prevents a small learning table’s convenient full scan from becoming a poor default in a larger operational automation tool.

A common trap

Assuming every attribute is an efficient query key ignores index design; identify the partition/sort key or suitable index before promising fast arbitrary lookups across all items.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Keys and access patterns

A DynamoDB table has a partition key and optionally a sort key. The complete key identifies an item. GetItem uses that key; Query retrieves a key-defined collection, while Scan examines a broader table and can become costly. Design keys from required access patterns rather than copying a relational schema blindly. A services table with string partition key service_id can fetch {"service_id":{"S":"api"}} directly; searching by another arbitrary attribute without an index is not the same efficient key lookup. Access-pattern design makes request cost and performance predictable and prevents a small learning table’s convenient full scan from becoming a poor default in a larger operational automation tool. Assuming every attribute is an efficient query key ignores index design; identify the partition/sort key or suitable index before promising fast arbitrary lookups across all items.

WORKED EXAMPLE
A services table with string partition key service_id can fetch {"service_id":{"S":"api"}} directly; searching by another arbitrary attribute without an index is not the same efficient key lookup.

Why this matters

Access-pattern design makes request cost and performance predictable and prevents a small learning table’s convenient full scan from becoming a poor default in a larger operational automation tool.

A common trap

Assuming every attribute is an efficient query key ignores index design; identify the partition/sort key or suitable index before promising fast arbitrary lookups across all items.

CRUD, conditions and consistency

PutItem writes an item and can replace an existing one at the same key. UpdateItem changes selected attributes and supports conditional expressions. DeleteItem removes by key. Strongly consistent reads are supported for eligible table/local-index reads, while global secondary indexes use eventually consistent reads; consistency affects observations after writes. Use a condition such as attribute_not_exists(service_id) to protect an insert from replacing an existing item, and use ConsistentRead for the eligible direct table read when verifying a just-written fixture. Conditional operations prevent lost updates and accidental replacements, while explicit read consistency keeps a delayed observation from being mistaken for failed persistence during a controlled CRUD test. Using PutItem to edit one attribute can drop omitted attributes by replacing the item; use UpdateItem for a partial change and design conditions when concurrent writers could overwrite one another’s decisions.

WORKED EXAMPLE
Use a condition such as attribute_not_exists(service_id) to protect an insert from replacing an existing item, and use ConsistentRead for the eligible direct table read when verifying a just-written fixture.

Why this matters

Conditional operations prevent lost updates and accidental replacements, while explicit read consistency keeps a delayed observation from being mistaken for failed persistence during a controlled CRUD test.

A common trap

Using PutItem to edit one attribute can drop omitted attributes by replacing the item; use UpdateItem for a partial change and design conditions when concurrent writers could overwrite one another’s decisions.

ElastiCache and cache-aside behavior

ElastiCache provides managed caching options whose engine and deployment features vary. In cache-aside, an application checks the cache, loads authoritative data on a miss and stores a value with a chosen lifetime. TTL, invalidation and failure handling determine staleness. Cache loss should not erase the only authoritative data unless the architecture explicitly treats it differently. For service status, a 30-second cache TTL can reduce reads but allow a stale value for part of that window; after an authoritative update, invalidate or refresh the cached key according to the chosen consistency requirement. A documented staleness budget makes caching a deliberate trade-off and prevents performance improvements from silently weakening correctness for a field that users expect to reflect current authoritative state. Treating a cache as automatically consistent storage can return obsolete data after an update; define TTL and invalidation and test cache outage behavior rather than assuming managed infrastructure knows the application’s freshness requirements.

WORKED EXAMPLE
For service status, a 30-second cache TTL can reduce reads but allow a stale value for part of that window; after an authoritative update, invalidate or refresh the cached key according to the chosen consistency requirement.

Why this matters

A documented staleness budget makes caching a deliberate trade-off and prevents performance improvements from silently weakening correctness for a field that users expect to reflect current authoritative state.

A common trap

Treating a cache as automatically consistent storage can return obsolete data after an update; define TTL and invalidation and test cache outage behavior rather than assuming managed infrastructure knows the application’s freshness requirements.

KEEP THESE WITH YOU

Today’s takeaways

Design keys from access needs.

Use conditions and partial updates deliberately.

Keep cache freshness explicit.

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