patrick_jones88
New Member
- Messages
- 60
- Reaction score
- 0
- Location
- Glasgow, UK
So about two years ago we started stuffing all our event payloads into a single jsonb column on Postgres. Felt amazing at the time. No migrations, no schema fights, ship whatever the client sends. I was the one pushing for it too, so this is on me.
Fast forward to now and the table is around 40M rows. Queries that used to be instant are taking 4 to 8 seconds because people keep filtering on nested keys and the GIN index has ballooned to something absurd. Half our analytics dashboards hit that column with ->> and @> operators and the planner just kind of shrugs at all of it.
The part that's really biting us is constraints. We have three different services writing into this thing and nobody agrees on whether a field is called userId, user_id or uid. So now we have application-level validation in four places and it drifts constantly. Found out last week that one service has been writing timestamps as strings for six months. Six months. Nobody noticed because nothing enforces anything.
I've started pulling the hot fields out into real columns with generated columns and a partial index, which works but it's tedious. And the backfill on 40M rows is not something I want to do during business hours, so it's been sitting in a ticket for three weeks.
I'm not saying JSONB is bad, it saved us a ton of time early on. But there's a point where the flexibility turns into a liability and I think we blew past it a year ago.
How do you all decide when a field graduates out of JSONB into a proper column? Do you set a rule up front or just wait until something breaks?