Why storing '2026-27' as a database key beats computing date ranges each time
A software developer writing for DEV Community explains a database design decision made while building a school and university discount redemption system. Rather than computing academic year date ranges dynamically on every query, each redemption row is stored with a short string key like '2026-27' representing the academic year it belongs to. This approach turns cap-usage checks into fast, indexed equality lookups instead of timestamp range scans. More importantly, it preserves historical accuracy: if the academic year start month is ever changed, stored period keys ensure past redemptions are not silently reclassified. The author draws a parallel to storing the price paid on an order row, arguing that any fact tied to a decision should be recorded at the moment it is made, not recomputed from rules that may later change.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in