Data Schema Evolution: Changing Your Data's Blueprint
Schema evolution is like updating a building's blueprint while it's occupied. You must change your data's structure without breaking apps or losing data. It's key for adding features that need new DB columns.
WHY IT EXISTS: Software is never finished. As applications evolve with new features and bug fixes, the underlying data structures—the schemas—must also change. Schema evolution provides a controlled process to modify a database's structure while preserving existing data and keeping the application running.
THE MENTAL MODEL: Think of a schema as the blueprint for a building. Schema evolution is the process of renovating that building while people are still living and working inside. You can't just knock down a load-bearing wall (a breaking change). You need a careful plan to add a new room (a new table or column) or rewire the electricity (change a data type) without disrupting the occupants (your applications and users).
HOW IT WORKS: Strategies depend on the type of change. Additive changes are safest: add a new column with a default value; old code ignores it, new code uses it. Subtractive changes, like deleting a column, are risky and require a multi-step process: first, deploy code that no longer reads or writes to the column, then, after all clients are updated, run a migration to drop it. Modifying a column's name or type is the most complex, often using an "expand and contract" pattern: add the new column, migrate data, switch the application to use the new column, and finally remove the old one.
WHEN TO USE IT: This is a constant activity in any long-lived project with a database or data store. It's triggered when you release a new version of your application, refactor code, or migrate data between systems. It applies to SQL databases, NoSQL document stores, and even file formats in a data lake like Parquet or Avro.
WHEN NOT TO USE IT: You don't really 'opt out' of evolution, but you can choose simpler paths. For throwaway prototypes or projects where you can afford to wipe all data, a formal, multi-stage evolution process is overkill. The key is to avoid making backward-incompatible changes on critical systems without a robust, phased rollout plan.
ONE CANONICAL EXAMPLE: A users table initially has id and email. To add a user's name, you make an additive change: add a new, nullable full_name column. New versions of the app can start writing to it. Old versions continue to work because the column is optional. You can then run a background job to backfill names for existing users. This avoids downtime and ensures both old and new clients function correctly during the transition.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.