Java Backend Interview Q&A← All stacks

Liquibase & Flyway — Interview Q&A Matrix

Parent stack: Persistence & Caching Technology: Liquibase & Flyway Levels: Junior · Architect Questions: 2

Each entry contains a Question, the Expected Depth, an Ideal Answer, and Red Flags.

Junior

Q1 — Schema migrations with Flyway and Liquibase

Question: Why use Flyway or Liquibase instead of running SQL by hand, and how do migrations work?

Expected Depth:

Ideal Answer:

sql
-- V2__add_order_status.sql
ALTER TABLE orders ADD COLUMN status text;

UPDATE orders SET status = 'PENDING' WHERE status IS NULL;
sql
-- R__active_orders_view.sql
CREATE OR REPLACE VIEW active_orders AS
SELECT id, customer_id, status
FROM orders
WHERE status IN ('PENDING', 'PAID');
yaml
databaseChangeLog:
  - changeSet:
      id: add-order-status-index
      author: platform-team
      preConditions:
        - onFail: MARK_RAN
        - not:
            - indexExists:
                indexName: idx_orders_status
      changes:
        - createIndex:
            tableName: orders
            indexName: idx_orders_status
            columns:
              - column:
                  name: status

Red Flags:


Architect

Q2 — Zero-downtime schema migrations at scale

Question: You must add a NOT NULL column and rename another on a 500M-row table used by live traffic, with no downtime. Design the migration process.

Expected Depth:

Ideal Answer:

sql
SET lock_timeout = '2s';
ALTER TABLE orders ADD COLUMN status_v2 text;
sql
UPDATE orders
SET status_v2 = status
WHERE id > :start_id
  AND id <= :end_id
  AND status_v2 IS NULL;
sql
SELECT count(*)
FROM orders
WHERE status_v2 IS NULL OR status_v2 IS DISTINCT FROM status;
sql
ALTER TABLE orders
    ADD CONSTRAINT orders_status_v2_nn
    CHECK (status_v2 IS NOT NULL) NOT VALID;

ALTER TABLE orders
    VALIDATE CONSTRAINT orders_status_v2_nn;

ALTER TABLE orders
    ALTER COLUMN status_v2 SET NOT NULL;
sql
CREATE INDEX CONCURRENTLY idx_orders_status_v2
ON orders (status_v2);

Red Flags:


Scoring Rubric

Level Pass bar
JuniorUses versioned migrations and understands checksums and history.
SeniorTests migrations and controls deployment ownership and failure handling.
ArchitectDesigns compatible, observable, zero-downtime schema changes at scale.