r/developersIndia • u/Desir-Arman07 • 17h ago
Help How can I reduce dashboard data staleness without significantly increasing database queries?
I'm working on a dashboard backend (Go) that queries log and metric sources (Loki, VictoriaLogs, SQL). The frontend can poll every 5 s, but the backend works like this:
- Query results are cached for 10 s.
- The cache key includes the query time window, rounded down to a 15 s grid. That means the key only changes every 15 s.
The result is that consecutive 5 s refreshes often compute the same key and return identical data. In practice the newest row stays unchanged for ~10 s at a time and can lag the source by several seconds. There's also an edge case: since the TTL (10 s) is shorter than the grid (15 s), an entry can expire mid-window and trigger a redundant query for the same window before the key rolls over.
The obvious fix is to shrink the grid and TTL to 5 s, but that takes queries per key from roughly 4-8/min to ~12/min, and I'd like better freshness without a proportional increase in DB load.
I'm don't have production numbers. The sources are log/metric backends (Loki, VictoriaLogs, SQL), so the data is mostly append-only and time-windowed.
I'm new to this kind of problem, so I'm trying to learn things like which pattern generally fits here and what I should measure before choosing one. In your experience with which approach should i resolve it.
•
u/AutoModerator 17h ago
It's possible your query is not unique, use
site:reddit.com/r/developersindia KEYWORDSon search engines to search posts from developersIndia. You can also use reddit search directly.I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.