DVA-C02 · Question #386
A company runs an ecommerce application on AWS. The application stores data in an Amazon Aurora database. A developer is adding a caching layer to the application. The caching strategy must ensure…
The correct answer is B. Implement a write-through strategy for every item that is created and updated. A write-through caching strategy updates the cache synchronously every time data is written to the database, ensuring the cache always reflects the most current value. This eliminates stale reads at the cost of slightly higher write latency.
Question
A company runs an ecommerce application on AWS. The application stores data in an Amazon Aurora database. A developer is adding a caching layer to the application. The caching strategy must ensure that the application always uses the most recent value for each data item. Which caching strategy will meet these requirements?
Options
- AImplement a TTL strategy for every item that is saved in the cache.
- BImplement a write-through strategy for every item that is created and updated.
- CImplement a lazy loading strategy for every item that is loaded.
- DImplement a read-through strategy for every item that is loaded.
How the community answered
(28 responses)- A4% (1)
- B75% (21)
- C7% (2)
- D14% (4)
Why each option
A write-through caching strategy updates the cache synchronously every time data is written to the database, ensuring the cache always reflects the most current value. This eliminates stale reads at the cost of slightly higher write latency.
A TTL strategy only invalidates cached items after a time period expires, meaning the cache can serve stale data for the entire duration of the TTL window, violating the most-recent-value requirement.
With write-through caching, every create or update operation writes to both the cache and the underlying Aurora database simultaneously. This guarantees that any subsequent read hits the cache and returns the latest value, satisfying the requirement for always using the most recent data.
Lazy loading only populates the cache on a cache miss by reading from the database; between writes and the next miss, the cache can hold stale data.
A read-through strategy also populates the cache only on a cache miss, so it can return stale data for items that were updated in the database since they were last cached.
Concept tested: Write-through caching strategy for data freshness
Source: https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/Strategies.html
Community Discussion
No community discussion yet for this question.