Constraint Driven Development
Submitted by Swanand Pagnis (@swanand) on Thursday, 28 February 2019
Technical level: Intermediate
An experience report on how DB constraints helped our team perform profound structural changes to our application data through 4 large refactorings that happened over 30 months.
Relational databases are robust, reliable, and battle-tested. However, they truly shine when it comes to maintaining data integrity. This talk demonstrates the powerful nature of constraints in the context of large scale data refactorings, with real-life examples and code samples, all to make a central point: They cannot be an afterthought. You have to make them a part of your development process, and you get rewarded for doing so.
Since the context is around four refactorings, the talk is also made up of as many sections.
- Migrating from Neo4j to PostgreSQL. (8 minutes)
- Changing primary keys from UUID to Integer while maintaining referential integrity. (7 minutes)
- Moving from a “shared and federated data” model to multi-tenant like “shared nothing” model. (8 minutes)
- Getting rid of a join-table in the most central relationship in the app, and using triggers in conjunction with constraints to being reliability into the process. (7 minutes)
Apart from talking about constraints, I will also touch upon “adjacent” principles that were a part of this process, such as idempotency, iterative development, and testability.
Intro and conclusion together: ~5 minutes.
Buffer time for adjustments: ~5 minutes.
This talk is most benefical to two kinds of people:
- Those who have prior experience building applications using a relational database
- Those who have built applications, but never with relational databases
Some experience or understanding of the process of writing web-based applications is required.
Swanand is a Principal Engineer at First.io, a Durham based startup. He is a self-proclaimed “gnosiophile” and a fan of continuous improvement. He loves writing software, building communities, and mentoring people. He’s currently helping people get better at PostgreSQL through https://postgres-workshop.com/