TimescaleDB for storing crash game rounds, worth the hassle?

mike_t_2019

Member
Messages
60
Reaction score
0
Location
Leeds, UK

Been logging every round from a few crash games into Postgres for about 14 months now. Not for anything sketchy, I just like having my own data instead of trusting some offshore site's "history" tab that only shows the last 50 rounds. Started off as a joke, now I've got ~40M rows and my queries are crawling.

Plain Postgres with daily partitions was fine up to maybe 5M rows. After that the INSERT bursts during a hot multiplier streak started choking, and any query that touches a 30 day window is basically a coffee break. Read about TimescaleDB hypertables, seemed like the obvious move, but the migration docs make it sound way cleaner than I suspect it actually is.

Anyone here actually running Timescale in prod? Curious what chunk intervals people landed on for time series that comes in bursts (mine is wildly uneven, like 400 rows/sec during peak, dead quiet at 4am). Also do you bother with their compression or just drop old chunks and keep a rollup table? I tried continuous aggregates once on a test box and the refresh lag confused the hell out of me.

Side note, this whole project started because I got sick of Ontario's idea of a "regulated" product. Can't even pull my own hand history without filing a ticket. So now I hoard data like a weirdo. Not sorry.

Anyway, if you've done this migration, how long did it take before you trusted it enough to point the app at it?

da_real_mvp

New Member
Messages
69
Reaction score
0
Location
Atlanta, GA

40M rows and daily partitions choking isn't a Timescale problem, that's an insert path problem. Before you migrate anything, go look at how you're actually writing. One INSERT per round over a single connection will die at exactly the scale you're describing, and no hypertable on earth fixes it. Batch it, or dump into an UNLOGGED staging table and merge on a schedule. And check your indexes! If you've got a plain btree on the timestamp column, every single insert is paying to update it. For append only time series like this a BRIN index does the same job for a fraction of the cost. I've watched people triple their write throughput just by making that one swap.

On chunk intervals, the default 7 days will make you sad. Rule of thumb is a chunk that fits comfortably in about 25% of RAM. At 400 rows/sec peaks, a 1 day chunk is like 30M+ rows and you're right back where you started. I'd start at 1 hour or 6 hours and tune from there. The burstiness doesn't really hurt you if the chunks are small, because the inserts land in a handful of chunks instead of touching one giant hot table.

Compression: yes, do it, but understand the tradeoff. Append only data compresses absurdly well and you can still query compressed chunks, you just can't UPDATE them. So if you ever need to correct a bad round, set up a policy so recent chunks stay uncompressed and only cold chunks get squeezed. And the continuous aggregate refresh lag thing, that's real and it's the #1 gotcha. What bites you is that by default the aggregate only returns materialized data, so you're staring at a number that's an hour stale and thinking your pipeline is broken. Set the aggregate to include real time data so the recent window reads from raw and older windows read from the rollup. Then it behaves the way your brain expects.

Honestly for a personal/project scale thing I'd try the BRIN + batching route first before you take on a migration. Cheaper test.

What's your write path look like right now? Single connection doing one insert per round, or are you already batching? And what's the box, spinning disk or NVMe? Because if it's disk I/O bound, all of the above is moot.

And yeah, the Ontario thing. I gave up trying to get my own hand histories out of there, they act like it's state secrets. Hoard away.

w0lfpack88

New Member
Messages
72
Reaction score
0
Location
Oslo, NO

lol the "hoard data like a weirdo" line hit home. I've got years of session logs in a CSV graveyard because I got sick of offshore books wiping their history tab every time they "upgrade the platform." ACMA blocks half the decent ones here anyway, so half my notes are just which VPN + PayID combo was still working that month. Not sorry either.

On the technical side, da_real_mvp is right that the insert path is the real problem, not Postgres. But I'd push back on jumping straight to Timescale. If it's append only and 90% of your queries are "give me the last 30 days," a rollup table refreshed every few minutes plus a BRIN on the raw table got me further than I expected. Way fewer moving parts to babysit at 2am when you're already tilted and don't feel like debugging a refresh job.

Also your compression sentence cut off mid word. What was the tradeoff you were gonna mention? That's the part I actually want to hear about. I read somewhere you can't do updates on compressed chunks and that alone scared me off, but if your data never changes maybe it's a non issue.

zer0cool99

New Member
Messages
67
Reaction score
0
Location
Seattle, WA

Re compression since w0lfpack88 asked and da_real_mvp's post got cut off mid sentence: the real tradeoff is you can't insert into a chunk once it's compressed, and you can't update or delete individual rows in it either. Newer versions technically let you, but it decompresses the whole chunk behind the scenes so it's painful. Whole game is only compressing chunks that are already cold. If your retention is "raw for 30 days then roll up," you compress everything past day 7 and never look at it again. Fine for append only. Not fine the day you want to backfill a correction on an old round.

1 hour chunks feels aggressive to me though. At 400/sec that's ~1.4M rows per chunk which is whatever, but at 4am you're spawning chunks with like 12 rows in them, and now you've got 24x the chunk count for the planner to chew through on a 30 day window. I landed at 6 hours and it was a decent middle ground, but my peaks aren't as violent as yours.

And yeah, the hoarding. Same reason here. The Curacao books I use wipe bet history every time they "upgrade the platform," which is code for "we swapped payment processors again." I've got spreadsheets going back to 2019 that double as a record of which VPN + PayID combo survived each ACMA block wave. Saved my arse in two bonus disputes where their own support swore the bets never existed. Disk is cheap, being gaslit by a support chat at 3am is not.

How are you doing the actual cutover though? Dual write for a few weeks or a one shot dump? That's the bit that'd keep me up, not the chunk sizing.

LisaW_

New Member
Messages
53
Reaction score
0
Location
Edinburgh, UK

ok so I'm basically 14 months behind you, just started logging my own rounds after getting burned by one of those history tabs that vanished mid session. This thread has been a lot.

da_real_mvp, you mentioned the BRIN swap tripling write throughput. Is that a straight drop in for a plain btree on the timestamp column, or do I need to rebuild something? I've got a btree on mine and honestly I'm not sure it's doing anything useful for append only data.

And w0lfpack88, the rollup table thing sounds way less terrifying than Timescale for someone at my level. How often are you refreshing yours? "Every few minutes" feels like it'd still eat CPU, unless I'm misunderstanding how light it is.

FrostyBear

New Member
Messages
67
Reaction score
0
Location
Brisbane, AU

zer0cool99 the 12-rows-at-4am thing is what's throwing me. I've only got like 2M rows total so I'm nowhere near this scale, but I set up 1 hour chunks after reading a blog post and now I'm looking at some chunks with basically nothing in them. Feels dumb. Does Postgres care or does it just sort itself out?

Also da_real_mvp, when you say BRIN does the same job for append only data, is that true if I'm still occasionally querying by game id and not just timestamp? I've got a btree on (game_id, created_at) and I'm scared to touch it because everything queries off it.

jt_loves_tacos

New Member
Messages
75
Reaction score
0
Location
Phoenix, AZ

FrostyBear, careful with the BRIN swap, it only does the same job when the column you index tracks physical insert order. Timestamp does, because you append in time order. game_id doesn't, you're writing rounds from all your games interleaved so the min/max ranges per block are basically useless and every query still hits most of them. So no, don't rip out your (game_id, created_at) btree for BRIN.

What you can do is keep both. The btree eats your filtered "show me this game" lookups, and a separate BRIN on created_at handles the "last 30 days across everything" scans for pennies. The BRIN is tiny so it's not like you're doubling your index maintenance.

And 1 hour chunks at 2M total rows is genuinely silly FrostyBear. You're spawning like 60 chunks a day for data that fits in RAM twice over. Go weekly or even monthly and stop overthinking it, nobody hands out medals for chunk granularity.

LisaW_ btree to BRIN is a drop in, you just create the BRIN and drop the old index, but do it on a maintenance window because building it the first time still scans the table.

ChrisM85

New Member
Messages
62
Reaction score
0
Location
Dublin, IE

Nobody actually answered the "how long before you trusted it" question so I'll take it. About three weeks of dual writing for me. Wrote to Postgres and Timescale in parallel, ran the same rollups against both every night, compared counts. Boring as hell, but I got burned once already by a migration that quietly ate rows. Turned out a batch loader was silently failing on a unique constraint and I only caught it because the two counts diverged. Point the app at it before you've done that and you're trusting vibes.

On chunks I half disagree with zer0cool99. Yeah the empty 4am chunks are ugly, but 6h doesn't save you as much as it sounds if your peak is as violent as OP's. What actually helped me was compression on anything past day 7 and leaving the interval alone. And nobody's mentioned disk IO yet, that workload goes IO bound way before it goes CPU bound. If this is sitting on some cheap VPS you'll feel it. Poking around the server admin section here saved me some grief when I was tuning mine:

https://websiteforums.info/forums/server-administration.3/

The hoarding thing though, yeah. The Curacao books wiping history on every "platform upgrade" is exactly why I started logging. Half my old spreadsheets are basically a forensic record of which payment processor they were running that month. Funny how the upgrade always seems to land the same week as a processor swap.

jt_loves_tacos, since you clearly know the planner side, does a BRIN on created_at actually get used on a 30 day window if the table also has a btree on (game_id, created_at)? I've always assumed the planner just grabs the btree and ignores the BRIN, but I never actually checked the plan.

ChrisM85

New Member
Messages
62
Reaction score
0
Location
Dublin, IE

jt_loves_tacos nailed the dual index thing but left out the annoying part. That btree on (game_id, created_at) is still paying on every insert because game_id leads the key, so the planner can't prune by time range until it's already walked the index. I flipped mine to (created_at, game_id) and my filtered lookups didn't get any slower while the range scans got way cheaper. Worth testing on a copy before you commit though, depends how selective your game_id actually is.

LisaW_ the rollup refresh only eats CPU if you're doing a full rebuild. Mine is incremental, just an INSERT INTO rollup SELECT ... WHERE created_at > last_cursor, runs every 3 minutes, and I've literally never seen it above like 8% on one core. If yours feels heavy you're probably doing DELETE + reinsert over the whole window and that's the whole problem. Fix the cursor, not the schedule.

w0lfpack88 the VPN + PayID spreadsheet thing hit way too close. Mine's a notes file that's basically a graveyard of dead payment rails. Interac e-Transfer held up until the books started flagging the same email address, then I'm back to cycling crypto on-ramps and eating spread on every hop. Half my log entries are just "which rail worked this week" at this point lol.

OP, what did you actually land on for chunk interval in the end? Curious if you went 1h like da_real_mvp or split the difference at 6h.

sarah_2891

New Member
Messages
50
Reaction score
0
Location
Denver, CO

The continuous aggregate refresh lag thing nobody touched, so: it's not broken, it's just that a CAGG only shows you data up to its last completed refresh bucket. If your bucket is 1 hour and you query "last 30 min," you get nothing until the hour rolls and the job fires. That's the confusion. You can set it to refresh on a shorter schedule but then you're basically paying for a materialized view that can't be stale, which defeats the point. Check the timescaledb_information.continuous_aggregates view for the actual refresh window before you assume it's dropping rows.

But honestly the rollup table crowd is underselling what they're giving up. w0lfpack88 and jt_loves_tacos are both right that it's fewer moving parts, and for "give me last 30 days" it's fine. But the whole reason you're hoarding 40M rows is so you can ask weird questions later, like "how does 2am behave differently than 9pm" or "did this change after that platform update." A fixed rollup bucket quietly decides those questions for you. I'd keep raw around longer than 30 days if disk allows, even compressed, and treat the rollup as a speed layer, not the source of truth.

ChrisM85 the three week dual write is the right call and I'll die on that hill. I did two weeks and still caught a mismatch on day 11. Nobody wants to find out their loader was silently dropping 3% of rows for a month.

And yeah the Ontario thing. Filing a ticket to see your own bets is genuinely unhinged. Half the reason I log is just to have a copy that some regulator or operator can't lose for me.

You must log in or register to reply here.