Data & Analytics
Cache Invalidation in Analytics Platforms: Balancing Performance and Accuracy
How filter identity and source changes determine whether a report can be reused
Owen Velasco · Applied AI & Software Engineer | AI Applications, Automation Platforms, APIs & Enterprise Integrations · Dec 4, 2026 · 4 min read
When I changed how MarketingOS represented a dashboard filter, the first requests after deployment had to rebuild some reports. Subsequent requests could use the cache again. The rollout made a useful point visible: a cache hit tells me how fast reuse is. It gives me very little evidence about the cost of answering a new question or whether the stored answer is still valid.
Analytics makes the second question especially important. People compare periods, investigate changes, and make spending decisions from these screens. A fast answer built for the wrong filter or against an outdated source can send that work in the wrong direction. I worked through cache identity and freshness as separate questions, then measured the cost when either forced a rebuild.
The request identifies which answer to reuse. Source versions establish whether that answer still applies.
Give equivalent filters one identity
Several controls can lead to the same reporting request. A default route can supply a year that another caller sends explicitly. A multiselect can return the same items in a different order. If the cache uses the raw URL or serializes arbitrary request objects, those differences can produce separate entries for equivalent reports.
MarketingOS normalized the filter representation. One deployment check confirmed that two forms of a year filter reached the same entry. The change to the case-type filter representation also produced cold entries for some views. Both observations belong in the rollout check. Canonicalization improves reuse once the identity is established, and changing an existing identity affects what happens on the first visit.
When designing a cache key, I start with the report, the applicable organization and access scope, its date range, and normalized filters. I sort and deduplicate selections only where the report treats them as sets. I also check the semantics of an omitted filter, an empty selection, and a default. They can map to one identity only if the report returns the same result for each. A separate report-definition version can be useful when the calculation changes without changing the query parameters. That is a design recommendation, not a description of every field in the MarketingOS keys.
Invalidate from the report’s dependencies
A sync job can write the same records repeatedly as it revisits a lookback period. If “last sync finished” governs freshness, identical imports can expire a valid report. A meaningful correction can go unnoticed in the opposite design if freshness depends only on the latest record date. Moving an existing call to a different acquisition source, for example, can change historical attribution without inserting a new call.
In MarketingOS, the reports had different dependencies. A call-only update was immaterial to one cost report. Other views could depend on call attribution without depending on unrelated downstream updates. I wanted to be able to name the inputs to each calculation and explain exactly which source mutation made a cached answer obsolete.
The later development work added a per-organization generation counter for call reporting. The idea was to advance the counter when reporting fields changed through an insert, a correction, or an attribution update. Identical re-upserts would leave it alone, and a rolled-back statement would publish no new generation. A report that uses call data can compare its stored generation with the current one. A report that does not use those fields can omit that dependency. That work was locally validated in the material I reviewed. I make no production performance claim for it.
Measure the cold path before moving it
One experiment put source collection behind a SQL function. The source identifiers matched for the audited scope, which gave me one level of parity. The test still timed out while assembling the JSON response. The production application continued to use its existing source path in that rollout, with the alternate SQL path and cache warming disabled.
Database-side computation can pay off when it reduces rows at the source, uses indexes well, or returns a compact aggregate. The work moves with it. Building a large nested document in PostgreSQL can consume database time and serialization resources even when the query plan selects the right records. I want to know where the time went: selecting rows, applying business rules, constructing the response, or transferring it. Each answer points to a different optimization.
Warming has a similarly specific role. It can move a known default request off a user’s critical path. If routine synchronization invalidates that report over and over, warming may simply move expensive work into a background process. I would measure the miss rate and the causes of misses before deciding whether to warm a report.
Validate meaning, freshness, and cost
I would start with a fixed input dataset and compare cached and uncached results at the level of the published metric, totals, filters, and completeness notes. Matching identifiers is a good intermediate check. It cannot catch every difference in classification and aggregation. I would then exercise equivalent filters, distinct filters, a relevant source mutation, and an irrelevant mutation. An identical synchronization replay should be an explicit test case because ordinary sync traffic can otherwise hide the problem.
Finally, I would check one cold request and a repeat for the same canonical scope. I would record the cache outcome and the time spent on actual evaluation so a warm path cannot disguise an expensive first load. The test I care most about combines those ideas. Change a field that the metric depends on, verify that the answer changes, then replay the same record and verify that the correct answer remains reusable.
cache invalidation · analytics architecture · reporting · data freshness
Related work
More of the systems behind this writing is on the Work and Contact pages.