Slide 1

Slide 1 text

Zero-Downtime SQL Database Schema Evolution for Continuous Deployment Michael de Jong

Slide 2

Slide 2 text

Deployment Continuous

Slide 3

Slide 3 text

Write code Push to master Run test suite Package deliverable Deploy into production

Slide 4

Slide 4 text

Write code Push to master Run test suite Package deliverable Deploy into production

Slide 5

Slide 5 text

Write code Push to master Run test suite Package deliverable Deploy into production

Slide 6

Slide 6 text

Write code Push to master Run test suite Package deliverable Deploy into production

Slide 7

Slide 7 text

Write code Push to master Run test suite Package deliverable Deploy into production

Slide 8

Slide 8 text

Write code Push to master Run test suite Package deliverable Deploy into production

Slide 9

Slide 9 text

Continuous Integration Write code Push to master Run test suite Package deliverable Deploy into production

Slide 10

Slide 10 text

Write code Push to master Run test suite Package deliverable Deploy into production Continuous Delivery

Slide 11

Slide 11 text

Write code Push to master Run test suite Package deliverable Deploy into production Continuous Deployment

Slide 12

Slide 12 text

SO WHAT’S THE Problem?

Slide 13

Slide 13 text

SQL Databases

Slide 14

Slide 14 text

Continuous Deployment Faster release cycles Quick bug-fixes A/B testing ACID transactions Rigid schema Constraints for consistency SQL Databases

Slide 15

Slide 15 text

Continuous Deployment Continuous change VS. Change? No thank you… SQL Databases

Slide 16

Slide 16 text

Deploying a new version of a web service into production is well understood.

Slide 17

Slide 17 text

How to deal with a SQL database when deploying a new version of a web service into production…

Slide 18

Slide 18 text

How to deal with a SQL database when deploying a new version of a web service into production… … not so much

Slide 19

Slide 19 text

“I deploying database schema changes into production!” — said no software engineer ever

Slide 20

Slide 20 text

Reason 1: DDL statements

Slide 21

Slide 21 text

Nemesis:

Slide 22

Slide 22 text

MySQL 5.5 MySQL 5.6 PostgreSQL 9.3 PostgreSQL 9.4 S1 Read-only Non-Blocking Blocking Blocking S2 Read-only Non-Blocking Non-Blocking Non-Blocking S3 Read-only Non-Blocking Non-Blocking Non-Blocking S4 Read-only Non-Blocking Non-Blocking Non-Blocking S5 Read-only Non-Blocking Non-Blocking Non-Blocking S6 Read-only Non-Blocking Non-Blocking Non-Blocking S7 N/A N/A Non-Blocking Non-Blocking S8 N/A N/A Non-Blocking Non-Blocking S9 N/A N/A Blocking Blocking S10 Read-only Read-only Non-Blocking Non-Blocking S11 Read-only Read-only Blocking Blocking S12 Non-Blocking Non-Blocking Non-Blocking Non-Blocking S13 Non-Blocking Non-Blocking Non-Blocking Non-Blocking S14 Read-only Read-only Blocking Blocking S15 Read-only Read-only Blocking Blocking S16 Read-only Non-Blocking Non-Blocking Non-Blocking S17 N/A N/A Non-Blocking Blocking S18 Blocking Non-Blocking Non-Blocking Non-Blocking S19 Non-Blocking Non-Blocking Non-Blocking Non-Blocking

Slide 23

Slide 23 text

Reason 2: Mixed-State

Slide 24

Slide 24 text

API

Slide 25

Slide 25 text

API API NEW

Slide 26

Slide 26 text

Reason 3: Referential Integrity

Slide 27

Slide 27 text

QuantumDB’s Approach

Slide 28

Slide 28 text

Imagine if you will… movies rentals customers

Slide 29

Slide 29 text

changelog.addChangeSet(“Add referral column to customers table”, addColumn(“customers”, “referred_by”, integer()), addForeignKey(“customers”, “referred_by”) .named(“customer_referred_by_fk”) .onDelete(NO_ACTION) .referencing(“customers”, “id”)); Defining changes

Slide 30

Slide 30 text

82fba53 - CURRENT STATE 2ef5c1a 80bfa11 - FINAL STATE ADD COLUMN ADD FOREIGN KEY Defining changes

Slide 31

Slide 31 text

movies rentals customers Evolving the database schema

Slide 32

Slide 32 text

movies rentals customers customers* Evolving the database schema

Slide 33

Slide 33 text

movies rentals rentals* customers customers* Evolving the database schema

Slide 34

Slide 34 text

movies rentals* customers* rentals customers Evolving the database schema

Slide 35

Slide 35 text

movies rentals* customers* rentals customers Evolving the database schema

Slide 36

Slide 36 text

movies rentals* customers* rentals customers Evolving the database schema

Slide 37

Slide 37 text

movies customers* rentals customers rentals* Evolving the database schema

Slide 38

Slide 38 text

Accessing the database movies rentals* customers* rentals customers 82fba53

Slide 39

Slide 39 text

80bfa11 82fba53 movies rentals* customers* rentals customers Accessing the database

Slide 40

Slide 40 text

Accessing the database Application Driver

Slide 41

Slide 41 text

Application Wrapper Driver Accessing the database

Slide 42

Slide 42 text

Connection connection = DriverManager.getConnection( “jdbc:postgresql://localhost:5432/database”, “username”, “password”); Connection connection = DriverManager.getConnection( “jdbc:quantumdb:postgresql://localhost:5432/database?version=80bfa11”, “username”, “password”); Accessing the database

Slide 43

Slide 43 text

SELECT * FROM rentals WHERE customer_id = 2372 AND return_date < NOW() AND returned = false; SELECT * FROM rentals* WHERE customer_id = 2372 AND return_date < NOW() AND returned = false; Accessing the database

Slide 44

Slide 44 text

movies customers* rentals customers rentals* Dropping a database schema

Slide 45

Slide 45 text

movies rentals* customers* rentals customers Dropping a database schema

Slide 46

Slide 46 text

movies rentals* customers* Dropping a database schema

Slide 47

Slide 47 text

80bfa11 movies rentals* customers* Dropping a database schema

Slide 48

Slide 48 text

Demo-Time!

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

LET’S Evaluate

Slide 62

Slide 62 text

#1 - DDL statements QuantumDB only applies DDL statements to tables which are not yet in use. Thus the client is never blocked by QuantumDB.

Slide 63

Slide 63 text

#2 - Mixed-State Database clients can only access the tables in their chosen version of the database schema.

Slide 64

Slide 64 text

#3 - Referential Integrity Foreign key constraints are always adhered to, and mirrored when needed.

Slide 65

Slide 65 text

Too good to be true?

Slide 66

Slide 66 text

Supported databases

Slide 67

Slide 67 text

SUPPORTED ADD COLUMN ALTER COLUMN DROP COLUMN CREATE TABLE COPY TABLE RENAME TABLE DROP TABLE ADD FOREIGN KEY DROP FOREIGN KEY CREATE INDEX DROP INDEX NOT (YET) SUPPORTED DML STATEMENTS ADD CHECK CONSTRAINT DROP CHECK CONSTRAINT DECOMPOSE TABLE * JOIN TABLE * MERGE TABLE * PARTITION TABLE * * Update Rewriting and Integrity Constraint Maintenance in a Schema Evolution Support System: PRISM++ Supported operations

Slide 68

Slide 68 text

Copying data is limited by disk I/O. We could actively throttle this based on some metric. Hardware limitations

Slide 69

Slide 69 text

• QuantumDB, which supports complex schema changes on multiple tables. • Maintains referential integrity. • Can use up to two database schemas in parallel. Contributions

Slide 70

Slide 70 text

• Do it in a non-destructive, non performance-degrading fashion. • Nemesis, which is able to benchmark various schema evolution scenarios. Contributions

Slide 71

Slide 71 text

QuantumDB quantumdb.io - @java_devver