Data caching stores a reusable copy of data or a computed result so future requests can be served faster or more cheaply. Materialisation persists a derived result that could otherwise be recomputed from source data, such as a summary table, pre-joined view, aggregate, feature set or search index.
A cache is valuable because it is not the source. That same fact is also its central risk.
Caches and materialised data improve performance by trading computation for stored state. Instead of repeatedly asking the authoritative system to calculate the same answer, a derived result is preserved and reused. The engineering challenge is to ensure that the performance gain does not silently turn yesterday’s answer into today’s apparent truth.
ARTICLE ID: DATA.MANAGEMENT.040
Canonical function: governed derived state for performance, reuse and bounded staleness
Owner boundary: this article owns caching, materialisation, invalidation and recomputation. Data Synchronisation and Reconciliation owns general multi-system convergence; Data Warehousing and Analytics owns historical analytical stores; Data APIs and Data Services owns machine-facing access interfaces.
The Simple Answer
A cache follows a simple idea:
Authoritative State → Derive Result → Store Copy → Serve Quickly → Detect Change → Invalidate or Refresh → Verify Freshness
The copy is useful only while its relationship to the source remains understood.
Why Cache?
- reduce latency;
- reduce repeated computation;
- reduce load on source systems;
- improve availability during temporary source pressure;
- serve repeated analytical queries efficiently;
- support local or geographic distribution;
- precompute expensive joins or aggregations;
- make machine-learning features reusable.
The economic value comes from avoiding repeated work while keeping staleness within acceptable bounds.
Cache vs Source of Truth
A cache should normally be reconstructible from authoritative data. If a cached value becomes the only surviving copy of a business fact, the architecture has accidentally promoted derived state into canonical state.
The source owns the fact. The cache owns a performance representation of that fact.
Materialised Views
A materialised view stores the result of a query so consumers do not need to recompute it every time.
Examples include:
- daily sales by product;
- student attendance summary;
- customer lifetime value;
- pre-joined order and product data;
- rolling operational metrics.
The materialised view should retain lineage to the source tables and transformation version that produced it.
Precomputation
Precomputation spends resources earlier so later reads become cheaper. This is useful when many users repeatedly ask similar questions.
The trade-off is that precomputed results must be refreshed when underlying data changes.
Cache Keys
A cache key identifies which request or logical state a cached value represents.
Good keys include every parameter that changes meaning. If currency, locale, permissions or model version affect the result but are absent from the key, one consumer can receive another consumer’s representation.
Key Collisions
A key collision occurs when two logically different results map to the same cache identity. This can create incorrect or even privacy-sensitive leakage.
Cache identity is therefore a data-modelling problem, not merely a performance setting.
Time to Live
A time-to-live, or TTL, defines how long a cached value may remain before expiry.
A suitable TTL depends on the receiver:
- public reference data may tolerate hours or days;
- product availability may need minutes;
- account balances may need much stronger freshness;
- historical statistics may change only after scheduled restatement.
One global TTL for all data is usually wrong.
Expiry Is Not Refresh
Expiry marks a cached value invalid or eligible for replacement. It does not guarantee that a fresh value is already available.
Systems should define what happens after expiry: synchronous recomputation, asynchronous refresh, stale serving, or failure.
Cache-Aside Pattern
In cache-aside designs, the application checks the cache first. On a miss, it reads from the source and places the result into the cache.
This is simple and flexible, but invalidation must still occur when source state changes.
Read-Through Caching
A read-through cache retrieves missing values from the underlying source automatically. The application interacts primarily with the caching layer.
This can simplify application logic but makes the cache infrastructure part of the critical data path.
Write-Through Caching
Write-through designs update cache and backing store in a coordinated path before acknowledging completion.
This can improve immediate consistency but increases write latency and still needs failure handling when one component succeeds and another does not.
Write-Behind Caching
Write-behind designs accept changes in the cache or intermediary state and persist them to the backing store later.
This can improve performance but promotes the cache into a temporary authority role. Durability, ordering, replay and failure recovery therefore become much more important.
Invalidation
Invalidation marks a cached value as no longer trustworthy after source state changes.
The famous difficulty of cache invalidation comes from one question: how does the derived copy know that the source fact it represents has changed?
Time-Based Invalidation
Time-based invalidation expires values after a TTL. It is simple, but staleness may persist until the timer ends.
This is appropriate where bounded staleness is acceptable.
Event-Based Invalidation
Event-based invalidation reacts when the source emits a relevant change event. It can reduce staleness but depends on reliable change capture and event delivery.
A missed invalidation event can create a permanently stale cache unless periodic reconciliation exists.
Version-Based Invalidation
Cached values can carry a source version or generation number. Consumers compare versions and reject stale entries when the source version advances.
This works well when source versions are stable and cheaply observable.
Manual Invalidation
Manual invalidation remains useful for exceptional corrections, but relying on people for ordinary cache coherence is fragile.
Emergency invalidation tools should record who triggered them, why, which keys or regions were affected and whether refresh succeeded.
Freshness Contracts
Every cache should have a receiver-facing freshness expectation.
- maximum staleness;
- refresh trigger;
- behaviour during source failure;
- whether stale data may be served;
- how freshness is exposed to the consumer.
See Data Contracts and Data Products.
Stale-While-Revalidate
Some systems serve a slightly stale value immediately while refreshing it in the background.
This can provide low latency and resilience where bounded staleness is acceptable. It is inappropriate where presenting stale state could cause material harm.
Cache Stampede
A cache stampede occurs when a popular value expires and many consumers simultaneously request recomputation, overwhelming the source.
Mitigations include:
- request coalescing;
- early refresh;
- jittered TTLs;
- locking;
- stale-while-revalidate;
- prewarming.
Prewarming
Prewarming fills caches before expected demand. It can be useful after deployment, failover or known traffic events.
Prewarming should not load obsolete or unauthorised values merely because they were popular previously.
Eviction
Caches have finite capacity. Eviction chooses which entries to remove.
Policies may favour recency, frequency, size or explicit priority. The right policy depends on access patterns and recomputation cost.
Hot Keys
A hot key receives disproportionate traffic and can overload one cache partition or source path.
Detection and sharding strategies may be needed for highly skewed workloads.
Distributed Caches
Distributed caches partition or replicate values across several nodes to scale capacity and throughput.
This introduces distributed-state questions: replica consistency, failover, rebalancing and partial partition loss.
Local vs Shared Cache
A local process cache is extremely fast but each application instance can hold different state. A shared cache centralises state but adds network latency and shared-service dependency.
Some systems use both layers and accept different freshness guarantees at each.
Consistency Models
Caches can be strongly coordinated, eventually consistent or explicitly stale within a defined window.
The model should follow consequence. A content recommendation can tolerate more staleness than an authorisation decision.
Never Cache Authorisation Carelessly
Security decisions can change rapidly when roles are revoked. If authorisation results are cached, TTL and invalidation should reflect the consequence of delayed revocation.
Security-sensitive caches should fail closed where stale access could expose protected data.
Materialised Aggregates
Analytical platforms often materialise aggregates such as daily revenue, monthly active users or attendance rates.
These aggregates must remain bound to the metric definition and source versions that produced them.
See Semantic Layers and Metric Governance.
Incremental Materialisation
Instead of recomputing a full table, incremental materialisation updates only affected partitions or records.
This improves efficiency but increases dependence on complete change detection. Periodic full reconciliation can catch missed incremental changes.
Full Rebuild
A full rebuild recomputes derived state from authoritative sources. It is expensive but conceptually powerful because it removes accumulated incremental drift.
Derived products should be rebuildable whenever practical.
Recomputation as Recovery
Because materialised data is derived, corruption can often be repaired by discarding the bad state and recomputing from source evidence.
This is only safe when source history and transformation versions remain available.
Search Indexes as Materialised State
A search index is a materialised representation optimised for retrieval. It should be reproducible from authoritative documents and indexing logic.
Reconciliation should detect missing, stale and revoked documents.
Vector Indexes as Materialised State
AI vector indexes are also materialised views. They derive chunks and embeddings from source content.
A vector index needs source lineage, embedding-model version, chunking version and deletion propagation.
See AI Data Management.
Feature Caches
Machine-learning systems may cache or materialise model features for repeated serving. Training and serving should use compatible feature definitions and versions.
Lineage
Every important materialised product should be traceable to:
- source datasets;
- source versions;
- transformation version;
- metric definition where relevant;
- refresh time;
- materialisation version;
- owner.
See Metadata and Data Lineage.
Observability
Useful cache and materialisation signals include:
- hit rate;
- miss rate;
- latency;
- eviction rate;
- refresh age;
- stale-read rate;
- invalidations;
- rebuild duration;
- source-to-cache version lag;
- materialisation failures.
Hit rate alone is not enough. A 99% hit rate on stale or unauthorised values is not success.
Testing
Tests should cover:
- key construction;
- expiry behaviour;
- invalidation after source change;
- permission-specific caching;
- concurrent refresh;
- source failure;
- full rebuild;
- incremental materialisation;
- reconciliation with source;
- old-version removal.
See Data Testing and Reliability Engineering.
Cache Poisoning
Cache poisoning occurs when incorrect or malicious data is inserted into a cache and then served repeatedly as if authoritative.
Controls can include validated source paths, signed or authenticated updates, bounded write authority and rapid purge capability.
Privacy
Caches create additional copies of data. Sensitive values can persist after the source changes unless invalidation and expiry are reliable.
Cache storage, logs and backups should follow the classification of the underlying data.
Deletion
When a source record is deleted or access is revoked, derived caches must be identified and invalidated according to their purpose and legal obligations.
A deletion that reaches the database but not the cache is incomplete from the receiver’s perspective.
Availability During Source Failure
Caches can improve resilience by serving previously computed values while the source is unavailable.
The service should make the freshness state explicit. Serving stale-but-known data can be better than failing for some uses and unacceptable for others.
Graceful Degradation
A system can define degraded modes:
- serve stale values with timestamp;
- serve only low-risk cached fields;
- disable write operations;
- fall back to a simpler representation;
- fail closed for security-sensitive decisions.
Cost
Caching saves compute and source load but creates storage, invalidation, replication and operational cost.
The economic question is:
Saved Computation + Reduced Latency + Reduced Source Load − Storage − Refresh − Complexity − Staleness Risk
See Data Economics and Valuation.
Education Example
An education portal materialises a daily class-attendance summary so teachers do not recompute millions of attendance events on every dashboard load. The summary stores source date, metric definition and refresh time.
If a late attendance correction arrives, the affected class-day partition is recomputed. A periodic full reconciliation checks that incremental updates have not drifted from the underlying events.
Commerce Example
An online store caches product details and availability separately. Descriptions may tolerate a longer TTL. Availability requires faster invalidation because stale stock can create failed orders.
One product does not need one freshness rule for every field.
AI Example
An AI system caches retrieved context for repeated questions. The cache key includes document-set version and access scope. When a source document is updated or revoked, the document-set version changes and old cached contexts become invalid.
This prevents an old answer from surviving merely because it was fast to reuse.
Common Failure Modes
- Cache becomes truth: derived state loses its source relationship.
- Key missing context: different users or versions receive the same cached result incorrectly.
- TTL by habit: expiry is chosen without receiver consequence.
- Invalidation event missed: stale state survives indefinitely.
- Hit-rate worship: performance looks excellent while freshness fails.
- Stampede: simultaneous expiry overwhelms the source.
- Incremental drift: missed changes accumulate without full reconciliation.
- Security cache lag: revoked access remains cached.
- Deletion stops at source: derived copies retain sensitive data.
- Materialisation without lineage: nobody can reproduce how the result was computed.
A Cache and Materialisation Checklist
- What authoritative source can rebuild this state?
- Why is caching or materialisation needed?
- What exactly does the cache key identify?
- What maximum staleness can the receiver tolerate?
- How is invalidation triggered?
- What happens if invalidation is missed?
- Can the state be fully rebuilt?
- How is incremental refresh reconciled?
- Are permissions and classifications preserved?
- How are deletions propagated?
- Is freshness visible to consumers?
- What happens during source failure?
- How are stampedes and hot keys controlled?
- Are source and transformation versions recorded?
- Can stale or ambiguous state fail closed where consequence is high?
A Maturity Ladder
- Cached: repeated values are stored for speed.
- Expired: TTLs bound ordinary staleness.
- Invalidated: source changes actively retire stale entries.
- Versioned: cached state is tied to source and transformation versions.
- Rebuildable: derived state can be recomputed from authority.
- Reconciled: incremental materialisations are checked independently.
- Observable: hit rate, freshness, lag and invalidation health are visible.
- Adaptive: workload, incidents and receiver needs continuously tune materialisation strategy.
The Deeper Principle: Performance Is a Managed Distance from Authority
Caching creates distance between the receiver and the authoritative source in exchange for speed, resilience or cost savings. That distance can be measured in time, versions or transformations.
Good caching does not pretend the distance is zero. It manages the distance explicitly through freshness contracts, invalidation, lineage and rebuildability so performance improves without turning derived state into untraceable truth.
Data Management Series
- Data Caching and Materialisation
- Data Synchronisation and Reconciliation
- Data APIs and Data Services
- Semantic Layers and Metric Governance
- AI Data Management
Final idea: cache and materialise for speed, but never lose the route back to authority. Every derived copy should know what it represents, how stale it may be, how it is invalidated, and how to prove that it can be rebuilt when trust is in doubt.
