Back to feed
Dev.to
Dev.to
5/11/2026
I added a grid_size column. Two months later I dropped it. What I learned about derived state in Postgres.

I added a grid_size column. Two months later I dropped it. What I learned about derived state in Postgres.

Short summary

Author added a grid_size column to a multiplayer bingo game schema but deleted it two months later after four production bugs traced to column drift. Derived state calculated at read time proved simpler and more reliable. Key pattern: start with the simplest schema encoding the invariant, profile before denormalizing.

  • Denormalized grid_size column fell out of sync with actual board state, causing four distinct bugs
  • Replaced with derived calculation using SQRT(jsonb_array_length(board)) at read time
  • Lesson: encoding invariants as separate columns allows illegal states; derive when cheap

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Explore more