SlideShare a Scribd company logo
1 of 26
Download to read offline
The best ways to (not)
break your database in
production.
Rotem Tamir
Go Israel Meetup
September 5th, 2022
Hello, world!
Rotem Tamir (37), father of two.
● Co-founder @ Ariga
● Ent, a Linux Foundation Project. (11.5k ⭐)
● Atlas. (1.8k ⭐)
● Ex-Nexar, Ex-ironSource
@rotemtam @_rtam
Agenda (and why we’re presenting here)
● How can schema migrations break production?
● CI for migration files with Atlas + Demo
● Building a linter for schema migration files with Go
● How Go tests go test (and why we adopted the same solution)
Why does it matter?
velocity stability
Experiment
Respond to change
Reduce “inventory”
DB downtime is expensive
Data-loss is disastrous
Why are (SQL) database outages hard to manage?
● Maintaining shared, persistent state
● Scaling out isn’t trivial (or slow)
● Rollbacks aren’t trivial
● Rebuild and deploy doesn’t work
How can schema migrations
break production?
Destructive changes
● Changes to a database schema that
result in loss of data.
● Accidental deletion of data can be
disastrous.
● Cannot be undone by reverse DDL
statements.
● MySQL/MariaDB do not support
transactional DDL, worsening the
effect of failed migrations.
ALTER TABLE `users`
DROP COLUMN
`email_address`;
Breaking changes
Changes to a database schema
that break the contract between
the consuming applications
(backends) and the database.
Also called “backwards
incompatible changes”.
Trivia: Even adding a column can
be a breaking change! (How?)
ALTER TABLE `users`
RENAME COLUMN `email_address` TO
`email`;
Table copy
Changes to a database schema
that cause the table to lock for
operations as data is being
restructured on disk.
If the operation is heavy and takes
a lot of time, this is effectively a self
inflicted Denial-of-Service.
ALTER TABLE `users`
MODIFY `email_address`
varchar(100);
In MySQL, changing a non-virtual columns type
requires a physical rewrite (copy) of the table.
Data-dependent changes
Changes to a database schema
that may fail due to constraint
violations and break a deployment
sequence.
Since not all DDL statements can
run in transactions, databases may
be left in an unknown state.
ALTER TABLE `example`.`orders`
ADD UNIQUE INDEX `idx_name`
(`name`);
This statement is considered data-dependent
because if the orders table contains duplicate values
on the name column we will not be able to add a
uniqueness constraint.
Solutions
● Policies + code review
● Seed / Full snapshot simulation
● ORM-specific (ananke/strong_migrations) , Runner-specific
(whiteclarkegroup-liquibase-linter)
ariga/atlas
(Terraform for Databases?)
Schema
Definition
(HCL)
Automatic
Migration
Planning
Linting
(CI)
Execution
{ our topic }
Demo
Using the Atlas Github Action to detect destructive changes in CI.
Building a linter for schema migration
files
The analysis package
The standard Go way of analyzing Go
code. Used by: vet, golangci-lint and
more.
The sqlcheck package
Supporting many types of databases
● We have common checks, but each database is different (even
different versions of the same engine behave differently).
● How do we avoid switch/case statement maintenance hell?
database/sql: Global driver registries
https://github.com/lib/pq/blob/master/conn.go
https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/database/sql/sql.go
gocloud.dev
● An open source project building libraries and tools to improve the
experience of developing for the cloud with Go.
● Maintained by Google.
● Go CDK provides commonly used, vendor-neutral generic APIs that
you can deploy across cloud providers.
Blob storage
● Change implementations
easily
● Just change the URL scheme:
○ mem://
○ s3://
○ gcs://
Registering Analyzers
Benefits of global driver registries
● Decoupling - infra code does not need to know about each
database avoiding awareness of which database we’re working
against.
● Ecosystem - drivers can be contributed without being part of the
“central” codebase
Testing CLI applications with testscript
● “Hidden gem” inside the Go
standard library codebase
● Used to test the Go toolchain
● Maintained by rogpeppe in
go-internal
● Uses txtar - a trivial
text based archive
format.
● Works in the Go
Playground!
Using testscript
● Sandbox env per test
● Custom commands
● Example (test_race.txt)
● Atlas Lint example
Questions?
@_rtam on twitter
atlasgo.io entgo.io ..and more
Also, we’re hiring gophers to work on:
Thank you.

More Related Content

Similar to All the ways to (not) break your database in production

Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12
Enkitec
 
Db As Behaving Badly... Worst Practices For Database Administrators Rod Colledge
Db As Behaving Badly... Worst Practices For Database Administrators Rod ColledgeDb As Behaving Badly... Worst Practices For Database Administrators Rod Colledge
Db As Behaving Badly... Worst Practices For Database Administrators Rod Colledge
sqlserver.co.il
 
MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014
Dave Stokes
 

Similar to All the ways to (not) break your database in production (20)

Frustration-Reduced PySpark: Data engineering with DataFrames
Frustration-Reduced PySpark: Data engineering with DataFramesFrustration-Reduced PySpark: Data engineering with DataFrames
Frustration-Reduced PySpark: Data engineering with DataFrames
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
 
Oracle GoldenGate
Oracle GoldenGateOracle GoldenGate
Oracle GoldenGate
 
Oracle Golden Gate Interview Questions
Oracle Golden Gate Interview QuestionsOracle Golden Gate Interview Questions
Oracle Golden Gate Interview Questions
 
QuestDB: ingesting a million time series per second on a single instance. Big...
QuestDB: ingesting a million time series per second on a single instance. Big...QuestDB: ingesting a million time series per second on a single instance. Big...
QuestDB: ingesting a million time series per second on a single instance. Big...
 
Liquibase få kontroll på dina databasförändringar
Liquibase   få kontroll på dina databasförändringarLiquibase   få kontroll på dina databasförändringar
Liquibase få kontroll på dina databasförändringar
 
Building a Database for the End of the World
Building a Database for the End of the WorldBuilding a Database for the End of the World
Building a Database for the End of the World
 
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
 
Operating and Supporting Delta Lake in Production
Operating and Supporting Delta Lake in ProductionOperating and Supporting Delta Lake in Production
Operating and Supporting Delta Lake in Production
 
Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12
 
Db As Behaving Badly... Worst Practices For Database Administrators Rod Colledge
Db As Behaving Badly... Worst Practices For Database Administrators Rod ColledgeDb As Behaving Badly... Worst Practices For Database Administrators Rod Colledge
Db As Behaving Badly... Worst Practices For Database Administrators Rod Colledge
 
Sql 2016
Sql 2016Sql 2016
Sql 2016
 
Obevo Javasig.pptx
Obevo Javasig.pptxObevo Javasig.pptx
Obevo Javasig.pptx
 
Insync10 goldengate
Insync10 goldengateInsync10 goldengate
Insync10 goldengate
 
Healthcare Claim Reimbursement using Apache Spark
Healthcare Claim Reimbursement using Apache SparkHealthcare Claim Reimbursement using Apache Spark
Healthcare Claim Reimbursement using Apache Spark
 
Professional SQL for Developers
Professional SQL for DevelopersProfessional SQL for Developers
Professional SQL for Developers
 
Are we there Yet?? (The long journey of Migrating from close source to opens...
Are we there Yet?? (The long journey of Migrating from close source to opens...Are we there Yet?? (The long journey of Migrating from close source to opens...
Are we there Yet?? (The long journey of Migrating from close source to opens...
 
11g R2
11g R211g R2
11g R2
 
MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014
 
Building the Petcare Data Platform using Delta Lake and 'Kyte': Our Spark ETL...
Building the Petcare Data Platform using Delta Lake and 'Kyte': Our Spark ETL...Building the Petcare Data Platform using Delta Lake and 'Kyte': Our Spark ETL...
Building the Petcare Data Platform using Delta Lake and 'Kyte': Our Spark ETL...
 

Recently uploaded

Recently uploaded (20)

Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 

All the ways to (not) break your database in production

  • 1. The best ways to (not) break your database in production. Rotem Tamir Go Israel Meetup September 5th, 2022
  • 2. Hello, world! Rotem Tamir (37), father of two. ● Co-founder @ Ariga ● Ent, a Linux Foundation Project. (11.5k ⭐) ● Atlas. (1.8k ⭐) ● Ex-Nexar, Ex-ironSource @rotemtam @_rtam
  • 3. Agenda (and why we’re presenting here) ● How can schema migrations break production? ● CI for migration files with Atlas + Demo ● Building a linter for schema migration files with Go ● How Go tests go test (and why we adopted the same solution)
  • 4. Why does it matter? velocity stability Experiment Respond to change Reduce “inventory” DB downtime is expensive Data-loss is disastrous
  • 5. Why are (SQL) database outages hard to manage? ● Maintaining shared, persistent state ● Scaling out isn’t trivial (or slow) ● Rollbacks aren’t trivial ● Rebuild and deploy doesn’t work
  • 6. How can schema migrations break production?
  • 7. Destructive changes ● Changes to a database schema that result in loss of data. ● Accidental deletion of data can be disastrous. ● Cannot be undone by reverse DDL statements. ● MySQL/MariaDB do not support transactional DDL, worsening the effect of failed migrations. ALTER TABLE `users` DROP COLUMN `email_address`;
  • 8. Breaking changes Changes to a database schema that break the contract between the consuming applications (backends) and the database. Also called “backwards incompatible changes”. Trivia: Even adding a column can be a breaking change! (How?) ALTER TABLE `users` RENAME COLUMN `email_address` TO `email`;
  • 9. Table copy Changes to a database schema that cause the table to lock for operations as data is being restructured on disk. If the operation is heavy and takes a lot of time, this is effectively a self inflicted Denial-of-Service. ALTER TABLE `users` MODIFY `email_address` varchar(100); In MySQL, changing a non-virtual columns type requires a physical rewrite (copy) of the table.
  • 10. Data-dependent changes Changes to a database schema that may fail due to constraint violations and break a deployment sequence. Since not all DDL statements can run in transactions, databases may be left in an unknown state. ALTER TABLE `example`.`orders` ADD UNIQUE INDEX `idx_name` (`name`); This statement is considered data-dependent because if the orders table contains duplicate values on the name column we will not be able to add a uniqueness constraint.
  • 11. Solutions ● Policies + code review ● Seed / Full snapshot simulation ● ORM-specific (ananke/strong_migrations) , Runner-specific (whiteclarkegroup-liquibase-linter)
  • 13. Demo Using the Atlas Github Action to detect destructive changes in CI.
  • 14. Building a linter for schema migration files
  • 15. The analysis package The standard Go way of analyzing Go code. Used by: vet, golangci-lint and more.
  • 17. Supporting many types of databases ● We have common checks, but each database is different (even different versions of the same engine behave differently). ● How do we avoid switch/case statement maintenance hell?
  • 18. database/sql: Global driver registries https://github.com/lib/pq/blob/master/conn.go https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/database/sql/sql.go
  • 19. gocloud.dev ● An open source project building libraries and tools to improve the experience of developing for the cloud with Go. ● Maintained by Google. ● Go CDK provides commonly used, vendor-neutral generic APIs that you can deploy across cloud providers.
  • 20. Blob storage ● Change implementations easily ● Just change the URL scheme: ○ mem:// ○ s3:// ○ gcs://
  • 22. Benefits of global driver registries ● Decoupling - infra code does not need to know about each database avoiding awareness of which database we’re working against. ● Ecosystem - drivers can be contributed without being part of the “central” codebase
  • 23. Testing CLI applications with testscript ● “Hidden gem” inside the Go standard library codebase ● Used to test the Go toolchain ● Maintained by rogpeppe in go-internal ● Uses txtar - a trivial text based archive format. ● Works in the Go Playground!
  • 24. Using testscript ● Sandbox env per test ● Custom commands ● Example (test_race.txt) ● Atlas Lint example
  • 25. Questions? @_rtam on twitter atlasgo.io entgo.io ..and more Also, we’re hiring gophers to work on: