keepcalculator

06 Numbers and Powers

Database Branching vs Separate Development Databases: Which?

Card No. 06·40414 · Updated · Standard formula, shown below

Database branching and separate development databases are two different strategies for managing schema changes and test data in software development. You should use database branching when you need isolated, version-controlled schema changes that can be merged and deployed automatically, and you should use separate development databases when you want full data isolation and manual control over environments. The right choice depends on your team’s size, deployment pipeline, and how much data each developer needs.

What Is Database Branching?

Database branching treats the schema (and sometimes seed data) like code. Instead of each developer having their own database, the schema is stored as migration scripts or declarative definitions in a version control system (like Git). A branch in the code repository corresponds to a branch in the schema. When you check out a feature branch, your local database is automatically migrated to match that branch’s schema. When you merge the branch, the migration is applied to the shared integration database.

Tools that support this approach include Flyway, Liquibase, and more advanced platforms like PlanetScale (for MySQL) or Neon (for Postgres) that offer built-in branching. These tools create a virtual copy of the database that is cheap to spin up and discard, often using storage snapshots rather than full copies.

What Are Separate Development Databases?

In the traditional approach, each developer (or each development environment) has its own full database instance. This could be a local Postgres, MySQL, or SQL Server running on a laptop, or a shared dev server where each developer has a separate schema or database. The schema is usually updated by running migration scripts manually or via a script that pulls latest changes from the repository.

The key difference is that the database is a separate resource from the code. It is not versioned with the code; instead, it evolves independently, and developers must coordinate to keep schemas in sync.

How They Work in Practice

With database branching, the workflow looks like this:

  • You create a branch in your version control system.
  • The branching tool creates a new database branch from the current main branch (or from a specific commit).
  • You make schema changes by adding migration files or editing declarative schema files in your code branch.
  • Your local development environment points to the database branch, and the tool automatically applies migrations when you switch branches.
  • When you merge your code branch, the database branch is merged into the main branch, and the migration is applied to the shared database.

With separate development databases, the workflow is:

  • Each developer has their own database instance (or schema) that they manage.
  • They pull the latest code from the repository, which includes migration scripts.
  • They run the migration scripts against their local database to update the schema.
  • If they need to reset data, they restore from a backup or run seed scripts.
  • When they commit code, they also commit the migration scripts, but the actual database changes are not automatically merged; the migration must be run against the shared integration database.

Key Differences: Isolation, Merging, and Data

The most significant difference is how changes are merged. Database branching allows schema changes to be merged like code, with conflict detection and resolution. Separate databases do not have a built-in merge mechanism; if two developers change the same column, they must manually resolve the conflict when they run migrations on the shared database.

Data isolation is another factor. With separate development databases, each developer has a completely independent copy of the data. They can insert, delete, or corrupt data without affecting anyone else. With database branching, the data is shared at the storage level (via snapshots), so writes are isolated, but the underlying data is a copy of the main branch at the time of branching. If you need to test with a large dataset, branching may use more storage, but modern tools use copy-on-write so it is often cheaper than full copies.

How to Choose: Factors to Consider

There is no one-size-fits-all answer, but these factors will guide your decision:

  • Team size: For a small team (1-5 developers), separate databases are simple and require no special tooling. For larger teams, branching reduces coordination overhead.
  • Deployment pipeline: If you use continuous integration and automated deployments, database branching fits naturally because schema changes are versioned and can be tested in a pipeline. If you deploy manually, separate databases may be easier.
  • Data sensitivity: If your development data contains sensitive information (even masked), you may prefer separate databases to control access. Branching tools often have access controls, but they add another layer to manage.
  • Cost and infrastructure: Separate databases require more storage and compute resources if each developer has a full instance. Branching can be cheaper if your database is large, because branches use snapshots.
  • Schema change frequency: If you change the schema frequently, branching helps avoid merge conflicts. If changes are rare, separate databases are fine.

Common Problems and Misconceptions

A common misconception is that database branching is only for cloud databases. While it is popular in cloud platforms, you can implement a similar workflow with local tools like Docker and Flyway by creating a new container for each branch. However, this is more manual and does not provide the same merge capabilities.

Another problem is that branching tools often struggle with large binary data or database-specific features (like stored procedures with state). Migrations must be written carefully to be idempotent and reversible, otherwise merging can fail.

With separate databases, the biggest problem is schema drift: developers forget to run migrations, or they manually alter their local schema, and then the shared database breaks. This is why many teams adopt migration tools even with separate databases.

Cost and Maintenance Comparison

Separate development databases have a predictable cost: each developer needs a database instance, which may be on a shared server or local machine. If you use a cloud database, the cost scales with the number of developers. Maintenance includes applying OS updates, managing backups, and ensuring connectivity.

Database branching tools typically charge per active branch or per storage used. The cost can be lower if you have many developers but few active branches. Maintenance is mostly on the tool side, but you must ensure the branching tool is compatible with your database engine and your CI/CD system.

Frequently Asked Questions

Can I use database branching with my existing Postgres/MySQL database?

Yes, but it depends on the tool. Some tools like PlanetScale and Neon are database-specific. For self-hosted databases, you can use migration tools like Flyway or Liquibase with a branching workflow, but you will need to manually create a new database from a snapshot for each branch.

What if I need to test with a large dataset (e.g., 100GB)?

Database branching is usually more efficient because it uses copy-on-write snapshots, so creating a branch does not duplicate the entire dataset. Separate databases would require copying 100GB for each developer, which is slow and expensive.

How do I handle merge conflicts with database branching?

Most branching tools do not automatically resolve schema conflicts. You will need to manually edit the migration scripts or declarative schema files to resolve conflicts, just like you would with code. Some tools provide a visual diff to help.

Is it possible to have both: separate databases and branching?

Yes, many teams use a hybrid approach. For example, each developer has a local database (separate), but they use migration scripts and a branching tool to manage schema changes. This gives the isolation of separate databases with the version control of branching.

Which approach is better for a small startup?

For a small startup with a simple schema and few developers, separate development databases are simpler and require no extra tooling. As the team grows and the schema becomes more complex, consider migrating to a branching workflow.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →