Home / Companies / Mergify / Blog / Post Details
Content Deep Dive

Two counters instead of a materialized view

Blog post from Mergify

Post Details
Company
Date Published
Author
-
Word Count
2,278
Company Posts That Month
10
Language
English
Hacker News Points
-
Post removed?
No
Summary

Rémy Duthu's blog post delves into the intricacies of building a custom metric rollup system on Postgres, emphasizing the limitations of using materialized views for handling high-frequency data updates. The author explains that while materialized views are useful for static data or infrequent updates, they fall short in scenarios where data is frequently written and then deleted, such as in their CI job metrics system. Instead of relying on materialized views, the team developed a two-writer, two-counter mechanism that effectively manages data retention and update efficiency by incrementally updating metrics with a combination of synchronous and asynchronous processes. This system utilizes a synchronous writer for immediate updates and an asynchronous writer for periodic recalculations, effectively balancing data freshness with computational efficiency. Duthu highlights the importance of using two counters instead of a boolean flag to avoid race conditions during asynchronous recalculations, ensuring that metrics remain accurate despite concurrent data writes. The blog concludes by recommending the use of materialized views only in scenarios where data changes infrequently, while advocating for their custom approach in high-write environments to maintain performance and accuracy.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
OpenTelemetry 1 1,075 169 52 +11%
Real-time 1 6,395 1,450 242 +6%
Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.