SlideShare a Scribd company logo
IMMUTABLEIMMUTABLE
INFRASTRUCTUREINFRASTRUCTURE
BEYONDSTATELESSBEYONDSTATELESS
By Jorge Dias
HOLABARCELONA!HOLABARCELONA!
JORGEDIASJORGEDIAS
Father , coder , polyglot , human .
Infrastructure engineer by Schibsted.
AGENDAAGENDA
Introduction to immutable infrastructure
Implementing it in practice
Application for stateful services
WHATISWHATIS
IMMUTABLEIMMUTABLE
INFRASTRUCTURE?INFRASTRUCTURE?
IMMUTABLEIMMUTABLE
adjective | im·mu·ta·ble |  (ˌ)i(m)-ˈmyü-tə-bəl 
not capable of or susceptible to change
PARADIGMPARADIGM
Components are replaced rather than changed
Build new servers on every deploy and discard the old ones
TRADITIONALINFRASTRUCTURETRADITIONALINFRASTRUCTURE
“THEOLDWAY”“THEOLDWAY”
Mutable
Infrastructure
Unique Servers
Heterogeneous
fleet
Configuration
Drift
Hard to reproduce
environment
Costly failure events
Mostly static
ANEWCHALLENGEANEWCHALLENGE
New tools are needed
Automation is a necessity
Architecture changes for apps
APPLICATIONARCHITECTUREAPPLICATIONARCHITECTURE
12FACTORAPP12FACTORAPP
General guidelines for building SAAS applications
Great ideas for working on the cloud
CONFIGCONFIG
Config is everything that is likely
to change between deploys
Separate your config from your code
Store config in the environment
Use environment variables
PROCESSESPROCESSES
Processes are stateless and share-nothing
No persistent data between requests
Filesystem can be used as a brief cache
DISPOSABILITYDISPOSABILITY
Processes are disposable
Processes shut down gracefully on SIGTERM
Processes should also be robust against sudden death
BUILD
Code + Dependencies 
CODE
RELEASE
CONFIG
RUN
Execute Processes
APP
Build + Configuration
CREATINGBUILDSCREATINGBUILDS
Immutable infrastructure - Beyond stateless
RELEASINGCODERELEASINGCODE
DynamoDB
KMS
DEPLOYMENTSTRATEGIESDEPLOYMENTSTRATEGIES
Rolling terminate
Blue/green deployments
Canary releases
STATEFULSERVICESSTATEFULSERVICES
CONTEXTCONTEXT
Storage team offers managed databases to internal teams
Small team of 5 engineers and 1 manager
10s of clusters in production
100s of servers
DATAHASTODATAHASTO
LIVESOMEWHERELIVESOMEWHERE
File system
Databases
IMMUTABLEDATABASES?IMMUTABLEDATABASES?
Kind of...
Treat the system like you have no state
Any node can die and the system must be OK
Embrace distributed systems
“Controlled chaos“™ through Continuous deployment
ISN'TTHATDANGEROUS?ISN'TTHATDANGEROUS?
Yours Truly
“ If we can’t kill a node in a controlled matter then
when it inevitably fails we’ll be in real trouble. ”
CREATINGACLUSTERCREATINGACLUSTER
NODELIFECYCLENODELIFECYCLE
Load configuration
Generate configuration files
Gathers information about the cluster from cloud
If it’s the first node bootstraps the cluster
Joins an existing cluster as a new node or replacement
Respond to healthcheck to indicate success
CASSANDRA-NEOPTOLEMUSCASSANDRA-NEOPTOLEMUS
In house solution alternative to Priam from Netflix
4000 loc (3500 python)
def main():
block_devices = storage.get_block_devices_by_priority()
storage.create_raid(block_devices)
...
seeds_manager = SeedsManager(cluster_name=cluster_name)
seed_ips = seeds_manager.list_seeds_private_ips()
cassandra_configs = CassandraConfigs(
cluster_name=cluster_name,
seed_ips=seed_ips,
....
)
cassandra_configs.generate_cassandra_yaml()
cassandra_configs.generate_cassandra_env_extra()
....
def _ip_to_replace(self):
cassandra_dc = EC2Snitch.get_datacenter()
cassandra_rack = EC2Snitch.get_rack()
...
dead_nodes = cluster.find_dead_nodes(cassandra_dc, cassandra_rack)
...
ips_to_replace = [
node.address
for node in dead_nodes
if not EC2Checks(self.region).is_alive(node.address)
]
if len(ips_to_replace) == 0:
return None
return ips_to_replace[0]
ZOOKEEPERCLUSTERZOOKEEPERCLUSTER
function main()
{
genZookeeperConfig "${clustername}" > /etc/zookeeper/zoo.cfg
....
enis=$(getAvailableEnis "zookeeper-${clustername}")
attachEni "${enis}"
....
local myid="$(getEniTag ${eni} ZookeeperId)"
echo "${myid}" > /var/lib/zookeeper/myid
local myrole="$(getZookeeperRole "${clustername}" "${myid}" )"
....
}
DEPLOYINGCHANGESDEPLOYINGCHANGES
DEPLOYINFRASTRUCTURESTACKDEPLOYINFRASTRUCTURESTACK
Create resources, permissions, network rules
ROLLINGUPDATESROLLINGUPDATES
Small framework extensible for many cluster types
Currently supports Cassandra, Kafka and Zookeeper
Cluster and nodes
Healthchecks at both levels
Implements updating algorithms
TERMINATINGNODESTERMINATINGNODES
Send signal to node to start shutdown
Wait for cleanup and node termination
Wait for new node to be spawn
Wait for the cluster recovery and proceed with next node
def rolling_terminate(cluster):
nodes = cluster.nodes
for node in cluster.nodes_to_upgrade():
cluster.wait_until_healthy()
node.terminate()
cluster.wait_until_healthy()
class Node(object):
def __init__(self, instance_id, session):
self.instance_id = instance_id
def is_healthy(self):
return self._instance.state['Name'] != "running":
def terminate(self):
....
class Cluster(object):
def __init__(self, name, session):
self.name = name
def wait_until_healthy(self):
while True:
if self.asg.capacity == len(self.healthy_nodes) and self.is_healthy():
break
time.sleep(10)
def healthy_nodes(self):
return [n for n in self.nodes if n.is_healthy()]
def is_healthy(self):
return True
class CassandraNode(Node):
def terminate(self):
self._disablebinary()
self._wait_for_hint_delivery()
self._drain_node()
super().terminate()
def is_healthy(self):
return super().is_healthy() and 
self._check_node_disk_usage() and 
self._check_node_hints() and 
self._check_node_compactions() and 
self._check_service_is_up()
class CassandraCluster(Cluster):
node_type = CassandraNode
def is_healthy(self):
ssm_command = "/opt/cassandra/bin/nodetool status | grep -c ^'UN '"
health = SSM.run(self.nodes, ssm_command)
return all(x == self.asg.capacity and x == len(self.healthy_nodes) 
for x in health)
class KafkaNode(Node):
def is_healthy(self):
return super().is_healthy() and self._kafka_server_is_up()
def _kafka_server_is_up(self):
try:
response = requests.get(
"http://{}:{}/".format(self.public_dns_name, 8000)
)
return response.status_code == 200
except RequestException:
return False
class KafkaCluster(Cluster):
node_type = KafkaNode
def is_healthy(self):
health = [self._get_kafka_cluster_status(node.public_dns_name, port=8000) 
for node in self.nodes]
return all(x == "green" for x in health)
@staticmethod
def _get_kafka_cluster_status(server_address, port, timeout):
response = requests.get(
"http://{}:{}/cluster".format(server_address, port)
)
return response.json()["status"]
OURTOOLSOURTOOLS
EMBRACEYOURCLOUDPROVIDEREMBRACEYOURCLOUDPROVIDER
We use many AWS services
Cloudformation
Systems Manager
DynamoDB
KMS
EC2
S3
PREPARINGFORDISASTERPREPARINGFORDISASTER
If you loose customers data you’re in BIG trouble
Developed a tool
soon to be opensourced
for Cassandra Backup
SUMMARYSUMMARY
ADVANTAGESADVANTAGES
Known state and less deployment failures
Testing infrastructure in isolation is possible
Consistent environments between dev/pre/pro
Easy to rollback
TRADEOFFSTRADEOFFS
High up-front investment
Rolling update of a whole cluster takes time
TAKEAWAYSTAKEAWAYS
Immutable infrastructure is a means to an end not a goal.
It’s not about the tools it’s about the ideas.
You can implement it gradually.
It may not be a good fit for you.
GRACIASGRACIAS
on Github
on Twitter
https://mrdias.com
@diasjorge
@dias_jorge

More Related Content

PDF
Mv unmasked.w.code.march.2013
EDB
 
PDF
Александр Терещук - Memory Analyzer Tool and memory optimization tips in Android
UA Mobile
 
PDF
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
yoyamasaki
 
PDF
The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...
DataStax
 
PPTX
Vert.x - Reactive & Distributed [Devoxx version]
Orkhan Gasimov
 
PDF
Ansible pill09wp
Ideato
 
PDF
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
OpenCredo
 
PDF
Es part 2 pdf no build
Erik Rose
 
Mv unmasked.w.code.march.2013
EDB
 
Александр Терещук - Memory Analyzer Tool and memory optimization tips in Android
UA Mobile
 
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
yoyamasaki
 
The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...
DataStax
 
Vert.x - Reactive & Distributed [Devoxx version]
Orkhan Gasimov
 
Ansible pill09wp
Ideato
 
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
OpenCredo
 
Es part 2 pdf no build
Erik Rose
 

Similar to Immutable infrastructure - Beyond stateless (20)

PDF
Automation with Ansible and Containers
Rodolfo Carvalho
 
PDF
MongoDB World 2019: Creating a Self-healing MongoDB Replica Set on GCP Comput...
MongoDB
 
PPTX
Terraform at Scale
Calvin French-Owen
 
PPTX
Testing Terraform
Nathen Harvey
 
PPTX
Terraform for azure: the good, the bad and the ugly -
Giulio Vian
 
PPTX
Terraform for azure: the good, the bad and the ugly -
Giulio Vian
 
PDF
Infrastructure-as-code: bridging the gap between Devs and Ops
Mykyta Protsenko
 
PDF
From android/ java to swift (2)
allanh0526
 
PDF
Paul Angus (ShapeBlue) - Push infrastructure with Ansible #DOXLON
Outlyer
 
PPTX
terraform cours intéressant et super fort
amar719595
 
ODP
Intro to cassandra
Aaron Ploetz
 
PPTX
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
ScyllaDB
 
PDF
Intro to Terraform
Josh Michielsen
 
PDF
ProxySQL at Scale on AWS.pdf
Aleksandr Kuzminsky
 
PDF
Terraform at Scale - All Day DevOps 2017
Jonathon Brouse
 
PPTX
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays
 
DOCX
#! usrbinpythonimport naoqiimport timeipaddress = 192..docx
katherncarlyle
 
PDF
Hadoop Integration in Cassandra
Jairam Chandar
 
PPTX
Ansible & CloudStack - Configuration Management
ShapeBlue
 
PDF
Swift - One step forward from Obj-C
Nissan Tsafrir
 
Automation with Ansible and Containers
Rodolfo Carvalho
 
MongoDB World 2019: Creating a Self-healing MongoDB Replica Set on GCP Comput...
MongoDB
 
Terraform at Scale
Calvin French-Owen
 
Testing Terraform
Nathen Harvey
 
Terraform for azure: the good, the bad and the ugly -
Giulio Vian
 
Terraform for azure: the good, the bad and the ugly -
Giulio Vian
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Mykyta Protsenko
 
From android/ java to swift (2)
allanh0526
 
Paul Angus (ShapeBlue) - Push infrastructure with Ansible #DOXLON
Outlyer
 
terraform cours intéressant et super fort
amar719595
 
Intro to cassandra
Aaron Ploetz
 
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
ScyllaDB
 
Intro to Terraform
Josh Michielsen
 
ProxySQL at Scale on AWS.pdf
Aleksandr Kuzminsky
 
Terraform at Scale - All Day DevOps 2017
Jonathon Brouse
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays
 
#! usrbinpythonimport naoqiimport timeipaddress = 192..docx
katherncarlyle
 
Hadoop Integration in Cassandra
Jairam Chandar
 
Ansible & CloudStack - Configuration Management
ShapeBlue
 
Swift - One step forward from Obj-C
Nissan Tsafrir
 
Ad

Recently uploaded (20)

PDF
All chapters of Strength of materials.ppt
girmabiniyam1234
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PPTX
Online Cab Booking and Management System.pptx
diptipaneri80
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PPT
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
All chapters of Strength of materials.ppt
girmabiniyam1234
 
Tunnel Ventilation System in Kanpur Metro
220105053
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Online Cab Booking and Management System.pptx
diptipaneri80
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
Inventory management chapter in automation and robotics.
atisht0104
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
Ad

Immutable infrastructure - Beyond stateless