AWS Certified Developer – Associate / Question #683 of 557

Question #683

A developer is implementing a caching solution for an e-commerce platform's inventory system using Amazon ElastiCache. The cached inventory data must reflect real-time stock levels to prevent overselling. Which caching strategy ensures that inventory updates are immediately reflected in both the database and the cache?

A

A lazy-loading cache

B

A write-behind cache

C

A read-through cache

D

A write-through cache

Explanation

The write-through cache strategy (D) is correct because it synchronously updates both the database and the cache whenever a write operation occurs. This guarantees that the cached inventory data always reflects the latest stock levels, which is critical for preventing overselling in real-time scenarios.

Why other options are incorrect:
- A. Lazy-loading cache: Only loads data into the cache on read misses, leading to potential stale data if the database is updated independently.
- B. Write-behind cache: Asynchronously updates the database after writing to the cache, risking data inconsistency if the database update fails.
- C. Read-through cache: Focuses on synchronizing reads but does not handle writes directly, leaving the cache outdated after database updates.

Key Points:
- Write-through ensures immediate consistency by updating both cache and database on writes.
- Real-time inventory systems require synchronous updates to avoid discrepancies.
- ElastiCache supports write-through patterns via application logic or integrations.

Answer

The correct answer is: D