SlideShare uma empresa Scribd logo
1 de 57
Baixar para ler offline
ø downtime
Jônatas Davi Paganini
jonatas
jonatasdp
8dev
teams
10 deploys / day
RD Station
+2m mail / day
+700 external services
integrations
+N callbacks
Availability is
REQUIRED
99,9%
99,5%
99,0%
98,6%
98,0%
97,0%
99,99%
00:43:00
03:36:00
07:12:00
10:00:00
14:24:00
21:36:00
00:04:32
Availability
99.999???
availability =
( total_time - timeout / total_time ) * 100
ødowntime
mindset
NO schedule
maintenance
avoid: all || nothing
build reversible things
build incremental migrations
RubyConf 2012
compatible versions
http://shipit.resultadosdigitais.com.br/blog/
migrando-com-zero-downtime
talk is <cheap>!
show me the code!!!
Migration
add_column :people, :full_name, :string
Update data
Person.all.each do |person|
person.full_name = "#{person.first_name} #{person.last_name}"
person.save
end
350 million updates!!!
WTF time?!
Let’s improve it!
Person.all.each do |person|
person.full_name = "#{person.first_name} #{person.last_name}"
person.save
end
Select RIGHT attributes!
Update 0.1
Person.select("id,first_name,last_name").each do |person|
person.full_name = "#{person.first_name} #{person.last_name}"
person.save
end
update_attribute instead of save
Update 0.2
Person.select("id,first_name,last_name").each do |person|
person.update_attribute "full_name", "#{person.first_name} #{person.last_name}"
end
find in batches
avoid transaction
overhead
Update 0.3
Person.select("id,first_name,last_name").find_in_batches do |people|
People.transaction do
people.each do |person|
person.update_attribute "full_name", "#{person.first_name} #{person.last_name}"
end
end
end
FAILURE resilient
Update 0.4
Person.where(full_name: nil).select("id,first_name,last_name").find_in_batches do |people|
People.transaction do
people.each do |person|
person.update_attribute "full_name", "#{person.first_name} #{person.last_name}"
end
end
end
explore connection pool
Update 0.5
update_sql = "UPDATE people set full_name ="
Person.where(full_name: nil).select("id,first_name,last_name").find_in_batches do |people|
People.transaction do
people.each(ActiveRecord::Base.connection_config[:pool]) do |person|
ActiveRecord::Base.connection_pool.with_connection do |conn|
set_full_name = conn.quote("#{person.first_name} #{person.last_name}")
conn.execute("#{update_sql} #{set_full_name} where id = #{person.id} ")
end
end
end
end
model hook
Model
class Person < ActiveRecord::Base
before_save :update_full_name
def update_full_name
self.full_name = "#{first_name} #{last_name}"
end
end
rollout control
Rollout
class Rollout
def enabled?(feature, context)
redis.sismember(feature, context)
rescue Redis::BaseError
false
end
def enable(feature, context)
redis.sadd(feature)
end
def disable(feature, context)
redis.srem(feature)
end
private
def redis
Redis::Namespace.new("rollout", redis: $redis)
end
end
rollout use
if:
before_save :update_full_name, if: -> { Rollout.enabled? "started_migration", "global" }
deploysteps
smoothly
steps
PR #1
add new column
PR #2
writeold & newcolumns
PR #3
migrate data
PR #4
read from new column
PR #5
remove old column
PR #6
remove rollout code, cache
Conclusion
Embrace migrations
● smoothly
● incremental
● safe
● resilient
Avoid migrations
● all || nothing
● ! roll outable features
REFERENCES
blog.codeship.com/rails-migrations-zero-downtime/
shipit.resultadosdigitais.com.br/blog/migrando-com-zero-downtime/
confreaks.tv/videos/railsconf2012-zero-downtime-deploys-for-rails-apps
?
Thanks!
jonatas
jonatasdp
ideia.me
shipit.resultadosdigitais.com.br

Mais conteúdo relacionado

Semelhante a ø Downtime migrations - Ruby Conf 2015

A Small Talk on Getting Big
A Small Talk on Getting BigA Small Talk on Getting Big
A Small Talk on Getting Big
britt
 

Semelhante a ø Downtime migrations - Ruby Conf 2015 (20)

Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Real World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsReal World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js Applications
 
GW SDAB Dev Tools 2012
GW SDAB Dev Tools 2012GW SDAB Dev Tools 2012
GW SDAB Dev Tools 2012
 
Taming the Tiger: Tips and Tricks for Using Telegraf
Taming the Tiger: Tips and Tricks for Using TelegrafTaming the Tiger: Tips and Tricks for Using Telegraf
Taming the Tiger: Tips and Tricks for Using Telegraf
 
FormatJS - JSConf Argentina
FormatJS - JSConf ArgentinaFormatJS - JSConf Argentina
FormatJS - JSConf Argentina
 
廣告系統在Docker/Mesos上的可靠性實踐
廣告系統在Docker/Mesos上的可靠性實踐廣告系統在Docker/Mesos上的可靠性實踐
廣告系統在Docker/Mesos上的可靠性實踐
 
mpi4py.pdf
mpi4py.pdfmpi4py.pdf
mpi4py.pdf
 
A Small Talk on Getting Big
A Small Talk on Getting BigA Small Talk on Getting Big
A Small Talk on Getting Big
 
4 Node.js Gotchas: What your ops team needs to know
4 Node.js Gotchas: What your ops team needs to know4 Node.js Gotchas: What your ops team needs to know
4 Node.js Gotchas: What your ops team needs to know
 
Sdndstw workshop-2017
Sdndstw workshop-2017Sdndstw workshop-2017
Sdndstw workshop-2017
 
All around the world, localization and internationalization on Android (Droid...
All around the world, localization and internationalization on Android (Droid...All around the world, localization and internationalization on Android (Droid...
All around the world, localization and internationalization on Android (Droid...
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
Técnicas avanzadas de programación Asíncrona - 2017
Técnicas avanzadas de programación Asíncrona - 2017Técnicas avanzadas de programación Asíncrona - 2017
Técnicas avanzadas de programación Asíncrona - 2017
 
AusNOG 2018 - The Robots are Coming!
AusNOG 2018 - The Robots are Coming!AusNOG 2018 - The Robots are Coming!
AusNOG 2018 - The Robots are Coming!
 
Who moved my pixels?!
Who moved my pixels?!Who moved my pixels?!
Who moved my pixels?!
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 
TAUS MT Showcase, Sovee Smart Engine 2.0, A Leap Beyond Base Moses Technology...
TAUS MT Showcase, Sovee Smart Engine 2.0, A Leap Beyond Base Moses Technology...TAUS MT Showcase, Sovee Smart Engine 2.0, A Leap Beyond Base Moses Technology...
TAUS MT Showcase, Sovee Smart Engine 2.0, A Leap Beyond Base Moses Technology...
 
Eventsourcing with PHP and MongoDB
Eventsourcing with PHP and MongoDBEventsourcing with PHP and MongoDB
Eventsourcing with PHP and MongoDB
 
Microservices Antipatterns
Microservices AntipatternsMicroservices Antipatterns
Microservices Antipatterns
 

Mais de Jônatas Paganini

Mais de Jônatas Paganini (19)

Extracting a Rails Engine to a separated application
Extracting a Rails Engine to a separated applicationExtracting a Rails Engine to a separated application
Extracting a Rails Engine to a separated application
 
Onboarding developers on a ful remote environment
Onboarding developers on a ful remote environmentOnboarding developers on a ful remote environment
Onboarding developers on a ful remote environment
 
TDC Floripa 2018 Dev Tests - weak specs
TDC Floripa 2018 Dev Tests - weak specsTDC Floripa 2018 Dev Tests - weak specs
TDC Floripa 2018 Dev Tests - weak specs
 
Floripa on Rails - dev workflow
Floripa on Rails - dev workflowFloripa on Rails - dev workflow
Floripa on Rails - dev workflow
 
Ensinando e aprendendo com desafios
Ensinando e aprendendo com desafiosEnsinando e aprendendo com desafios
Ensinando e aprendendo com desafios
 
Go Lang migrating billions of documents
Go Lang  migrating billions of documentsGo Lang  migrating billions of documents
Go Lang migrating billions of documents
 
Otimizando tempo de build: performance da suíte de testes
Otimizando tempo de build: performance da suíte de testesOtimizando tempo de build: performance da suíte de testes
Otimizando tempo de build: performance da suíte de testes
 
XP - eXtreme Programming - 2010
XP - eXtreme Programming - 2010XP - eXtreme Programming - 2010
XP - eXtreme Programming - 2010
 
Apresentação sobre Rails - 2010
Apresentação sobre Rails - 2010Apresentação sobre Rails - 2010
Apresentação sobre Rails - 2010
 
Tech for non techs
Tech for non techsTech for non techs
Tech for non techs
 
Otimizando tempo de build: performance da suíte de testes
Otimizando tempo de build: performance da suíte de testesOtimizando tempo de build: performance da suíte de testes
Otimizando tempo de build: performance da suíte de testes
 
4 ferramentas para acompanhar seu app em produção pelo slack
4 ferramentas para acompanhar seu app em produção pelo slack4 ferramentas para acompanhar seu app em produção pelo slack
4 ferramentas para acompanhar seu app em produção pelo slack
 
Concurrency in Ruby
Concurrency in RubyConcurrency in Ruby
Concurrency in Ruby
 
Quando descobri que era programador
Quando descobri que era programadorQuando descobri que era programador
Quando descobri que era programador
 
Life hacks for productivity
Life hacks for productivityLife hacks for productivity
Life hacks for productivity
 
Tdc cloud computing - RDStation experiences
Tdc cloud computing - RDStation experiencesTdc cloud computing - RDStation experiences
Tdc cloud computing - RDStation experiences
 
Life hacks for productivity
Life hacks for productivityLife hacks for productivity
Life hacks for productivity
 
Dicas para uma boa impressão 3D
Dicas para uma boa impressão 3DDicas para uma boa impressão 3D
Dicas para uma boa impressão 3D
 
ø Downtime migrations
ø Downtime migrationsø Downtime migrations
ø Downtime migrations
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

ø Downtime migrations - Ruby Conf 2015