Cloud concept · Updated

Write-Through Caching - Write-through caching updates the cache and the backing data store synchronously as part of the write operation.

In short

Write-through caching populates or refreshes cached data when that data is written, rather than waiting for a later read miss. It can improve subsequent read performance and reduce database read load, but adds work to the write path and requires explicit handling of failures and concurrent updates.

Cloud Concepts Hub →

6 key aspects of Write-Through Caching

Write-through caching exchanges additional write-path work and coordination for write-time cache population and faster subsequent reads.

01
Synchronous write-time population

The normal write path updates both persistent storage and the cache before reporting full success. This makes newly written data available for subsequent cache reads without waiting for a read miss.

02
Persistent backing store

The database remains authoritative, and persistence is not deferred as it is with write-back caching. Cache loss should not mean loss of successfully persisted business data.

03
Read acceleration with write overhead

Repeated reads of recently written data can avoid database queries, but each write incurs additional cache work. Measure the benefit against write latency, cache capacity, and operating cost.

04
Explicit consistency controls

Separate database and cache operations are not automatically atomic. Handle partial failures, out-of-order updates, and writers that bypass the cache integration.

05
Complementary read-miss handling

Combine write-through with cache-aside or read-through behavior to load missing entries. Expiration, eviction, and cache replacement still produce misses.

06
Defined failure and recovery policy

Decide whether cache failures fail the write operation or trigger a documented fallback after database persistence. Use bounded retries and repair mechanisms without assuming that an error means the database write was rolled back.

Cloud services for Write-Through Caching

An application can pair Amazon RDS with Amazon ElastiCache, committing relational changes and synchronously refreshing the relevant cache entries. Read-miss logic retrieves uncached data from RDS, while failure handling addresses cache outages and partial updates. For DynamoDB workloads, Amazon DynamoDB Accelerator provides an integrated write-through path for supported writes sent through DAX, with separate behavior for item caching, query caching, and strongly consistent reads. These are alternative implementations, not components that must all be deployed together. In either approach, route relevant writes through the chosen integration and measure read savings against added latency, cache expense, and recovery complexity.

Amazon ElastiCacheAmazon ElastiCache

Provides a shared in-memory cache that applications can use alongside a database. For a typical ElastiCache-backed database cache, application code implements the write-through sequence; ElastiCache does not automatically intercept arbitrary database writes.

Amazon RDSAmazon RDS

Can serve as the authoritative relational backing store for an application-managed write-through cache. The application coordinates committed database changes with cache updates; RDS does not automatically keep an external ElastiCache cache synchronized.

Write-Through Caching exam questions

Real practice exam questions on Write-Through Caching, with the correct answer and its explanation. Answer them with every option in the exam simulator.

DVA-C02

A delivery application stores routing rules in a relational database and uses Amazon ElastiCache for Redis OSS to cache individual rules. Dispatchers frequently read a rule immediately after an administrator creates or edits it. Currently, these first reads miss the cache and query the database, causing latency spikes.

The database must remain the authoritative store. During normal operation, the first read after a successful create or edit must retrieve the committed rule from the cache without querying the database, even if the rule was not previously cached. The team can accept additional latency for administrative writes. Updates to each rule are serialized. Assume no cache failures, expirations, or evictions during these operations.

Which change should a developer make?

Show answerCORRECT ANSWER

Commit the rule to the database, set its cache key to the committed value whether or not the key already exists, and return success only after the cache update completes.

This implements write-through caching in the application. The write path persists the rule and populates or refreshes the cache before acknowledging success. Under the stated assumptions, the next read is a cache hit, including for newly created rules. The trade-off is additional write latency.

SAP-C03

A sports media company stores immutable match summaries in Amazon DynamoDB. An API running across multiple Availability Zones serves the summaries through a shared Amazon ElastiCache for Valkey cache. Each newly published summary receives thousands of reads within seconds. The first reads after publication currently miss the cache and cause a spike in DynamoDB read traffic.

Each publication request includes a unique summary ID and an immutable payload. Publishers retry timed-out requests with the same ID and payload. A notification service starts directing readers to a summary only after the publication API returns success. The company can accept increased publication latency, but a successful publication must mean that the summary is durably stored and already available in the cache. Cache entries might expire or be evicted later, so reads must still support cache misses. The database and cache do not support a shared transaction.

Which implementation meets these requirements, including when a cache operation fails after a database write succeeds?

Show answerCORRECT ANSWER

Conditionally insert the summary into DynamoDB, then synchronously populate ElastiCache before returning success. If the cache operation fails, leave the request retryable. On retry, verify that an existing DynamoDB item has the same payload and attempt cache population again before returning success. Continue loading from DynamoDB on read misses.

This implements write-through caching in the application: persistence and cache population must both complete before publication succeeds. The stable summary ID supports idempotent retries, but an existing database item does not cause cache population to be skipped. A cache failure does not require rolling back the durable item. Cache-aside reads handle later expiration or eviction.

SAA-C03

A transportation company stores editable route schedules in Amazon RDS for PostgreSQL and caches them in Amazon ElastiCache. Dispatchers repeatedly read schedules after editing them. The cache reduces database read load enough to avoid increasing the DB instance size.

The application currently replaces the cached schedule before submitting the database transaction. Occasionally, a database constraint rejects an edit, but dispatchers continue to see that rejected edit in the cache. Updates to each route are serialized by the application.

The company requires that rejected edits never become visible through the cache. During normal operation, each successfully acknowledged edit must also leave the updated schedule cached so that subsequent reads do not need to query RDS. Additional latency on edits is acceptable.

Which change should a solutions architect recommend?

Show answerCORRECT ANSWER

Commit the schedule update to RDS first. After a successful commit, replace the cached schedule with the committed value and acknowledge success only after the cache update succeeds.

This implements write-through caching in the application. Committing to RDS first prevents database-rejected edits from entering the cache. Updating the cache before acknowledging success leaves the revised schedule available for subsequent reads, preserving the reduction in database read load.

Practice Write-Through Caching in a full exam

Questions on Write-Through Caching in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

What is Write-Through Caching

3 min read

Write-through caching is a caching strategy in which a write updates both the backing data store and the cache before the operation is acknowledged as fully successful. The backing store remains the authoritative source of data. Depending on the implementation, a cache component forwards writes to the database, or application code coordinates the two updates. Unlike write-back caching, write-through does not intentionally acknowledge a write while leaving persistence to a later background operation.

In a common cloud application implementation, the application commits a database update, writes the committed value into a shared cache, and then returns success. For example, a product service might update a product description in a relational database and immediately replace the corresponding cached product object. Subsequent requests can retrieve that object from memory instead of repeating the database query. Writing the database first avoids exposing a cache value for a database transaction that ultimately fails, although it does not make the two updates atomic.

Write-through and cache-aside are not mutually exclusive. An application can populate the cache on writes and also use cache-aside logic on reads: check the cache, fetch from the database on a miss, and populate the cache. This combination handles existing records that have never been cached, expired entries, evictions, and cache restarts. Write-through alone does not preload an entire database or ensure that every read will be a cache hit.

The main performance trade-off is additional write latency and cache traffic. A write must complete the necessary database and cache operations, while repeated reads can become faster and place less load on the database. This is useful when recently updated objects are frequently read. It is less attractive when most written objects are never read again, because those writes consume cache capacity without producing useful hits. Evaluate cache cost against avoided database reads, database scaling requirements, hit ratio, eviction rate, and application latency rather than assuming caching always reduces total cost.

Synchronous updates do not automatically provide strong consistency across independent systems. A database commit can succeed while the cache update fails, leaving a stale entry. Concurrent writers can also update the cache out of order, and a reader loading an older database value can race with a newer write. Use appropriate per-key coordination, version-aware cache updates, or other concurrency controls, and define a recovery policy for partial failures. Time-to-live settings limit how long an entry remains cached but do not guarantee that it is current before expiration. Database changes that bypass the write-through path also require coordination or invalidation.

For resilience, keep the cache disposable and plan for database reads during cache outages. Strict write-through behavior makes cache availability part of write availability; a deliberate fallback policy may instead allow a committed database write to succeed while invalidating or repairing affected cache entries. That fallback weakens the normal synchronous cache-update contract and must be designed explicitly. Use bounded timeouts, idempotent retries, and protection against a surge of cache misses overwhelming the database. In architecture questions, choose write-through for write-time cache population and fast subsequent reads, not for lower write latency, fewer database writes, or automatic cross-system transactions.

Learn Write-Through Caching in lessons

4 short lessons on Write-Through Caching in 2 certification courses.

Open the lessons