DVA-C02 Question 103
Single answerYou are developing an e-commerce application that uses Amazon DynamoDB as the database and Amazon ElastiCache for caching frequently accessed product details. To improve performance while ensuring that the cache remains synchronized with the database, which caching strategy should you implement?
- A
Write-through caching
- B
Lazy loading
- C
Read-through caching
- D
Cache aside
Show answer and explanation
Correct answer: A
Explanation
In this scenario, the primary requirement is to ensure that the cache remains synchronized with the database to provide consistent data. Write-through caching is the best strategy for this use case as it ensures that every write operation to the database is also reflected in the cache. Other strategies, like lazy loading, read-through, or cache aside, either prioritize performance or rely on manual cache management but do not inherently ensure synchronization after writes.
- A. Correct.
Write-through caching ensures that every write operation to the database is immediately written to the cache as well, keeping the cache in sync with the database. This is suitable for scenarios where data consistency is critical.
- B. Incorrect.
Lazy loading caches the data only when it is requested and not found in the cache. While it reduces initial load on the cache, it doesn't ensure that the cache is always synchronized with the database.
- C. Incorrect.
Read-through caching involves fetching data directly from the cache, and if the data is not in the cache, it is fetched from the database and then written to the cache. This does not directly handle synchronization during a write operation.
- D. Incorrect.
Cache aside is a strategy where the application manages when to fetch and update the cache. It does not automatically synchronize the cache during database writes, which can lead to stale data in certain scenarios.