Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How does Liquibase track changes, and how does it differ from Flyway in approach?

Liquibase describes changes as changeSets inside changelog files written in XML, YAML, JSON or SQL, and identifies each changeSet by its id, author and file path. It records applied changeSets with a checksum in DATABASECHANGELOG and uses DATABASECHANGELOGLOCK so only one process migrates at a time. Unlike Flyway's plain versioned SQL files, Liquibase can generate database-specific SQL from abstract change types and offers rollback definitions, contexts, labels and preconditions; Spring Boot runs it at startup from spring.liquibase.change-log.

Why this question is asked

Flyway and Liquibase solve the same problem, keeping the database schema in step with the code, and both are well supported by Spring Boot. Teams often pick one by habit, and engineers who know one assume the other works the same way. It mostly does, but the model behind it is different, and that difference explains when each is the better choice. Interviewers ask this to see whether we understand the model, not only the syntax. In this answer, we will look at how Liquibase organises changes, how it tracks them in its two tables, what its abstract change types and extra features give us, how that compares with Flyway, and how Spring Boot runs it.

1ChangeLogs and ChangeSets

In Liquibase, the unit of change is a changeSet, a small group of changes that are applied together. ChangeSets live in changelog files, and a master changelog usually includes the others in order. A changelog can be written in XML, YAML, JSON or as formatted SQL with special comments.

Each changeSet is identified by three things together: its id, its author and the path of the file it is in. There is no global version number as in Flyway. Liquibase applies changeSets in the order they appear in the changelogs, and it decides whether one has run by looking up that triple.

YAML
# db/changelog/db.changelog-master.yaml
databaseChangeLog:
- include:
file: db/changelog/changes/001-customer.yaml
# db/changelog/changes/001-customer.yaml
databaseChangeLog:
- changeSet:
id: create-customer
author: anna
changes:
- createTable:
tableName: customer
columns:
- column: { name: id, type: bigint, constraints: { primaryKey: true } }
- column: { name: email, type: varchar(255) }
rollback:
- dropTable: { tableName: customer }

Notice that the change is written as createTable with columns, not as SQL. That is the abstract style. The same changeSet could have been written as raw SQL inside a sql change, and many teams do exactly that.

2How Liquibase Tracks What Has Run

Liquibase creates two tables in the target database. DATABASECHANGELOG records every applied changeSet: its id, author, filename, the date it ran, the order of execution, an MD5 checksum of its content and a few other columns such as the contexts and labels in effect. On each update, Liquibase compares the changelog with this table, validates checksums of applied changeSets, and runs the ones not yet recorded.

DATABASECHANGELOGLOCK has a single row with a LOCKED flag. Before updating, Liquibase sets it to true with the host that took it, and sets it back afterwards. If another instance starts at the same time, it sees the lock and waits, so two instances never apply the same changeSet concurrently. The flag lives in a normal table, so if a process is killed while holding it, the lock stays set until someone clears it.

Like Flyway, Liquibase refuses to proceed if an applied changeSet was edited, because its checksum no longer matches. Liquibase also offers attributes that change this behaviour on purpose: runOnChange reruns a changeSet whenever its content changes, which suits views, and runAlways runs it on every update.

3Abstract Change Types, Rollback, Contexts and Preconditions

The abstract change types are Liquibase's main difference. A createTable or addColumn change is translated into the right SQL for the target database, so one changelog can create the same schema on PostgreSQL, Oracle and SQL Server, with types and syntax adjusted. Products that must ship on several databases benefit most from this.

Because Liquibase knows what a change means, it can also undo many of them. For a createTable it can generate the dropTable rollback automatically; for others we write a rollback block, as in the example. The rollback command then reverts the database to a tag, a date or a number of changeSets.

Contexts and labels let a changeSet run only in some situations, for example test data with context test, applied only when we run with that context. Preconditions are checks that run before a changeSet, such as tableExists or a SQL query, and can skip the changeSet, mark it as run or stop the update if the database is not in the expected state.

4How This Differs From Flyway

Flyway's model is a folder of SQL files with a version in each file name, applied in version order. What we write is exactly what runs, so a reviewer reads the SQL that will hit the database. That simplicity is its strength. Liquibase's model is a list of described changes that it turns into SQL, with more control over when and where each runs.

Liquibase and Flyway side by side
AspectLiquibaseFlyway
Unit of changechangeSet: id + author + fileversioned file: V3__name.sql
FormatsXML, YAML, JSON, SQLSQL (plus Java migrations)
Orderorder in the changelogsversion number in the file name
History tableDATABASECHANGELOGflyway_schema_history
Concurrency guardDATABASECHANGELOGLOCK rowdatabase lock taken during migrate
Multi-database SQLgenerated from abstract change typeswritten per database
Rollbackrollback blocks, many automaticwrite a new forward migration
Conditional runscontexts, labels, preconditionsplaceholders and locations

Neither is better in general. A team that targets one database and likes reviewing plain SQL usually finds Flyway simpler. A team that ships to several database engines, needs rollback scripts as part of its release process, or wants preconditions to guard changes in varied customer installations often finds Liquibase's extra structure worth it. Both support Java-based changes and both have commercial editions with additional features, whose terms change over time, so check the current editions before relying on one.

5Running Liquibase in Spring Boot

With liquibase-core on the classpath (and, in Spring Boot 4, the Liquibase starter, since auto-configuration moved into separate modules; check your version), Spring Boot runs a Liquibase update at startup using the application's DataSource, before JPA starts. The master changelog is set with spring.liquibase.change-log and defaults to classpath:/db/changelog/db.changelog-master.yaml.

Properties
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
spring.liquibase.contexts=prod
spring.jpa.hibernate.ddl-auto=validate

Other properties set contexts, labels, the default schema or a separate user for migrations. As with Flyway, Hibernate should only validate the schema, so that Liquibase is the only tool that changes it.

6Follow-up questions

Why does the file path matter in a changeSet's identity?

Because Liquibase looks up applied changeSets by id, author and filename. Moving or renaming a changelog file makes all its changeSets look new, and Liquibase would try to run them again. The logicalFilePath attribute fixes the recorded path, so files can be reorganised safely.

Can Liquibase use plain SQL like Flyway?

Yes. A formatted SQL changelog starts with a --liquibase formatted sql comment, and each changeSet begins with a --changeset author:id comment, with optional rollback comments. Many teams use this style to keep reviews in SQL while keeping Liquibase's tracking and features.

Is Liquibase rollback a safe way to undo a production release?

Only for changes that lose nothing. Rolling back an added column drops it and its data, and rolling back a data change may be impossible. In production, most teams still prefer a new forward change, and keep rollback for test environments or carefully reviewed cases.

7Conclusion

In this answer, we saw that Liquibase organises changes as changeSets in XML, YAML, JSON or SQL changelogs, identified by id, author and file path, records them with checksums in DATABASECHANGELOG and guards concurrent runs with DATABASECHANGELOGLOCK. Its abstract change types generate database-specific SQL, and it adds rollback, contexts, labels and preconditions, while Flyway stays with simpler versioned plain SQL. Spring Boot runs Liquibase at startup from spring.liquibase.change-log.

What to say in the interviewAbout 80 seconds aloud

Open with

Liquibase models changes as changeSets inside changelog files, which can be XML, YAML, JSON or formatted SQL, usually with a master changelog that includes the others. Each changeSet is identified by its id, its author and the path of its file, and changeSets run in the order they appear.

Then, if they want more

Liquibase records applied changeSets in DATABASECHANGELOG, with an MD5 checksum so edits to applied changes are detected, and it uses a one-row DATABASECHANGELOGLOCK table as a lock so only one instance migrates at a time. The big difference from Flyway is the abstraction.

Flyway is versioned plain SQL files: what I write is exactly what runs, which is simple to review.

Liquibase can describe a change as createTable or addColumn and generate the right SQL for each database, and it adds rollback definitions, many of them automatic, contexts and labels to run changes only in certain environments, and preconditions that check the database before a change.

So I would pick Flyway for a single-database service where plain SQL is enough, and Liquibase when I need multiple databases, rollback or conditional changes. In Spring Boot, with Liquibase on the classpath, it runs at startup before JPA, from spring.liquibase.change-log, which defaults to db/changelog/db.changelog-master.yaml, and I set ddl-auto to validate.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 4
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does Liquibase track changes, and how does it differ from Flyway in approach?": https://scrivio-interview-library.netlify.app/databases/schema-migration/bfc79b6a24/