Implemented a catalogue‑driven deep‑merge
Implemented a catalogue‑driven deep‑merge for stored JSON
preferences, preventing missing‑key crashes as the schema evolves.
2025

Situation. The platform stores JSON preferences — notification
settings and the like — as a user's saved values laid over a set of
defaults. The original merge did that at a single level. The problem
shows up later: add a new key to the defaults, and rows saved before
that key existed simply don't have it. Then some client code reads
that field, gets undefined, and falls over — for exactly the users
who've been around longest.

Task. Evolving the preference schema had to be safe, so that adding
a setting could never break the people who signed up before it
existed.

Action. The single‑level merge was replaced with a deep‑merge driven
by the defaults as a catalogue. The defaults are treated as the
authoritative list of every key that should exist; the user's stored
values are merged recursively on top, so anything in the catalogue
is guaranteed to come out present, whether or not it was in the
saved blob. Add a key to the defaults and it appears in every
existing row's effective preferences automatically, nested keys
included. It rolled in through a migration so existing data got the
benefit straight away rather than waiting to be rewritten.

Result. Preferences can grow without fear. Adding a setting no
longer risks an undefined‑field crash in the client, and the
frontend stopped needing defensive checks scattered around every
place it reads a preference. It also gave the rest of the platform a
dependable way to extend any stored‑JSON blob — the pattern, not
just the one fix.

Categories:
1Backend Engineering	/categories/backend/	engineer.company	70
1Databases	/categories/databases/	engineer.company	70
1PostgreSQL	/categories/postgresql/	engineer.company	70
1Data Governance	/categories/data-governance/	engineer.company	70
1Migrations & Modernization	/categories/migration/	engineer.company	70

Services:
1Backend & API Development	/services/backend-development/	engineer.company	70
1Database Design & Modeling	/services/database-design/	engineer.company	70
1Data Governance & Quality	/services/data-governance/	engineer.company	70

hThis page on the web	URL:https://engineer.company/portfolio/implemented-a-catalogue-driven-deep-merge/	engineer.company	70
