第1页
Resilient Routing and Discovery
Simon Eskildsen, Shopify @Sirupsen
第3页
Shopify
Docker in Production serving the below for 1+ year
165,000+
ACTIVE SHOPIFY MERCHANTS
200+
DEVELOPERS
DATACENTERS
3000+
CONTAINERS RUNNING AT ANY TIME
12+
DEPLOYS PER DAY
10,000+
MAX CHECKOUTS PER MINUTE
$8 BILLION+
CUMULATIVE GMV
500+
SERVERS
Ruby on Rails
10+ years old
300M unique visits/month
LEAGUE OF APPLE, EBAY AND AMAZON
第4页
Building reliable bridges in large distributed systems
第5页
Cross DC Networking
Complexity
Cross Regional Networking Same Rack Networking
Inter process
Reliability
In process
第6页
Resiliency
Discovery
Routing
第7页
Reliability is your success metric for discovery and routing.
第8页
Shopify started this journey in the fall of 2014
第9页
Resiliency
Building a reliable system from unreliable components
第10页
(Micro)service equation
Uptime = AN
Number of services
Availability per service Total availability
第11页
Availability
100 90 80 70
10 50 100 500 1000
Services
99.98
99.99
99.999
99.95
第12页
MySQL Shard MySQL Master
Kafka External HTTP API redis-sessions
Resiliency Matrix
Checkout Unavailable Available Available Degraded Unavailable
Admin Unavailable Unavailable Degraded Available Unavailable
Storefront Degraded Available Available Unavailable Degraded
第13页
Objectives for large distributed systems
Building reliable systems from unreliable components
Explore resiliency, service discovery, routing, orchestration and the relationship between them
Recognizing and avoiding premature optimizations and overcompensation
第14页
Application should be designed to handle fallbacks
第16页
search
carts
sessions
cdn mysql
第17页
Avoid HTTP 500 for single service failing
.. or suffer the faith of the (micro)service equation
第18页
Sessions data store unavailable Customer signed out
第19页
Simulate TCP conditions with Toxiproxy
curl -i -d '{"enabled":true, "latency":1000}' \ localhost:8474/proxies/redis/downstream/toxics/latency
curl -i -X DELETE localhost:8474/proxies/redis
Toxiproxy[:mysql_master].downstream(:latency, latency: 1000).apply do Shop.first # this takes at least 1s
end
Toxiproxy[/redis/].down do session[:user_id] # this will throw an exception
end
https://github.com/shopify/toxiproxy
第20页
With fallbacks the system is still vulnerable to slowness.
ECONNREFUSED is a luxury, slowness is the killer.
第21页
Little’s law
第22页
Infrastructure operating normally
400 RPS 0.01s
0.01s 0.01s 0.01s 0.01s
0.002s
0.001s
0.01s
第23页
Database latency increases by 10x, throughput drops 10x
0.020s 0.10s
40 RPS 0.10s
0.10s 0.10s 0.10s
0.001s
0.01s
第24页
Beating Little’s law is your first priority as you add services
第25页
Resiliency Toolkits
Bulk Heads, Circuit Breakers, ..
Release It book
twitter/finagle
shopify/semian
netflix/hystr25 ix
第26页
26
第27页
Resiliency Maturity Pyramid
Region Gorilla
Latency Monkey
Kill Nodes (Chaos Monkey)
Production Practise Days (Games)
Resiliency Patterns
Application-Specific Fallbacks Toxiproxy tests and matrix
Testing with mocks
No resiliency effort
第28页
Discovery
第29页
Infrastructure source of truth
Services
Instances of services
Metadata
Deployed revision, leader, ..
Orchestration
Aid to make things happen across components
第30页
Location
Global
Geo-replicated discovery
Regional
Single datacenter
第31页
Discovery Backbone Properties
No single point of failure
Stale reads better than no reads: A > C Reads order of magnitude larger than writes
Fast convergence
第32页
New and Old School
Consul
DNS
Zookeeper Chef, Puppet, ..
Eureka Etcd
Network Hardcoded values
第33页
Pure DNS for as long as you can. Still works for us. Don’t overcompensate.
第34页
Pure DNS
Resilient
Failovers?
Simple
Slow convergence
API Supported
Not a data store Not for orchestration
第35页
Global discovery and orchestration most pressing issue for Shopify
第36页
Orchestration of datacenter failovers
Too many Sources of Truth
Component Network MySQL
Application Redis
Load Balancers
Source of Truth NetEng? DBAs?
Cookbooks Cookbooks Hardcode value in config file
第37页
Routing shops to the right datacenter
DNS: shop.walrustoys.com
CNAME walrustoys.myshopify.com
IPs for DC 2
Map shop to DC
第38页
DNS problematic when..
Multiple owners of data
Fast converge
Lots of change in instances
第39页
Zookeeper
Scalable stale reads Not complete discovery
Consistent
Complex clients
Orchestration Trusted
Operational burden Shoehorn
第40页
Complex client problem
Connecting directly risky Proxy pattern
Dumping to files
Stale reads
第41页
Routing
第42页
Routing responsibilities
Load balance
Protect applications against unhealthy resources: circuit breaker, bulk heads, rate limiting, …
Receive upstreams from discovery layer
第43页
Trusted
Scriptable
Resiliency
Dynamic upstreams
Discovery built in
TCP Library/Proxy
yours OS nginx haproxy vulcand
finagle smartstack
Don’t do this
Of course
It’s perfect
I got it
Easy Obviously, it’s Go
YES YES Maybe? YES
3rd party (ngx-lua). Not complete (no TCP
support).
Possible for HTTP via ngx-lua. No TCP yet
Sidekick for new upstreams.
Manipulate existing via ngx-lua
No, try via sidekick/ ngx-lua
Sidekick and reloads
Lua support in master
Not scriptable, only rate limiting built-in
(with iptables wizardry), manipulate
No, try via sidekick
existing admin socket
Landed in 1.9.0, stabilized in nginx+
Built as L4
middlewares, requires forking
SOME, only circuit breaker
Beautiful HTTP API
etcd support
No, only supports HTTP currently (not in
ROADMAP.md)
Proxy Proxy Proxy
YES, completely centered around
plugins
YES, sophisticated FailFast module
YES
Zookeeper support
Application-level
Library, requires JVM
Somewhat
However much HAProxy is, adapters
NO, same as HAProxy
YES
Zookeeper support Yes, uses HAProxy Proxy + discovery
第44页
With a polyglot stack, we just use simple proxies and DNS
第45页
Current Stack
Discovery
DNS Server
Chef
Zookeeper
Discoverable
Through proxy
ZK Proxy
第46页
Future Stack
Discovery
Server
DNS
Zookeeper
Discoverable
Through proxy
ZK Proxy
第47页
Docker’s future role in discovery, routing and resiliency
第48页
Final remarks
Figure out service discovery value for your company, don’t overcompensate—your metric is reliability
Infrastructure teams own integration points, don’t leave it up to everyone to jump in
Build resiliency into the system, don’t make it opt in, be able to reason about entire system’s state and test
第49页
Thank you
Simon Eskildsen, Shopify @Sirupsen
第50页
Server by Konstantin Velichko from the Noun Project basket by Ben Rex Furneaux from the Noun Project container by Creative Stall from the Noun Project
people by Wilson Joseph from the Noun Project mesh network by Lance Weisser from the Noun Project
Conductor by By Luis Prado from the Noun Project Jar by Yazmin Alanix from the Noun Project
Broken Chain by Simon Martin from the Noun Project Book by Ben Rex Furneaux from the Noun Project
network by Jessica Coccimiglio from the Noun Project server by Creative Stall from the Noun Project
components by icons.design from the Noun Project switch button by Marco Olgio from the Noun Project
Pile of leaves (autumn) by Aarthi Ramamurthy Bridge by Toreham Sharman from the Noun Project collaboration by Alex Kwa from the Noun Project converge by Creative Stall from the Noun Project
change by Jorge Mateo from the Noun Project tag by Rohith M S from the Noun Project
whale by Christopher T. Howlett from the Noun Project file by Marlou Latourre from the Noun Project
Signpost by Dmitry Mirolyubov from the Noun Project Arrow by Zlatko Najdenovski from the Noun Project
Chef by Ross Sokolovski from the Noun Project