Resilience, Service-Discovery and Z-D Deployment Bodo - - PowerPoint PPT Presentation

resilience service discovery and z d deployment
SMART_READER_LITE
LIVE PREVIEW

Resilience, Service-Discovery and Z-D Deployment Bodo - - PowerPoint PPT Presentation

Resilience, Service-Discovery and Z-D Deployment Bodo Junglas, York Xylander Who is leanovate? 2 100 25 people, HQ in Kreuzberg Mission: Build learning organizaIons


slide-1
SLIDE 1

Resilience, ¡Service-­‑Discovery ¡ and ¡Z-­‑D ¡Deployment

Bodo ¡Junglas, ¡York ¡Xylander

slide-2
SLIDE 2 100

Who ¡is ¡leanovate?

2

25 ¡people, ¡HQ ¡in ¡Kreuzberg Mission: ¡Build ¡learning ¡organizaIons

slide-3
SLIDE 3 100

Dev ¡ Java,Scala, ¡SPA,.. Meth ¡

Kanban, ¡Scrum, ¡Lean*,..

What ¡do ¡we ¡do?

3

ConsulIng Coaching Training Doing

slide-4
SLIDE 4 100

Promises ¡of ¡µServices ¡architectures

4

Independent ¡(parallel) ¡development Independent ¡release ¡cycles Independent ¡scaling

slide-5
SLIDE 5 100

Challenges ¡of ¡µServices ¡architectures

5

  • Developing & Running
  • Configuring
  • Debugging
  • Deploying
  • Discovering
  • Resilience

Tough ¡to ¡learn ¡& ¡understand!

slide-6
SLIDE 6

Microzon: ¡ A ¡lab ¡for ¡µServices

hYps://github.com/leanovate/microzon

slide-7
SLIDE 7 1001

Case ¡Study: ¡Microzon-­‑Shop ¡

  • Browse ¡through ¡catalog ¡
  • Select ¡product ¡
  • Put ¡into ¡cart ¡
  • Checkout

7

DEMO

slide-8
SLIDE 8 1001

Case ¡Study: ¡Microzon-­‑Shop

8

Web Facade

Customer Product Cart Billing

Load-Balancer / Firewall

mysql mongo mysql mysql

slide-9
SLIDE 9 1001

Technology-­‑Babylon ¡

9

Customer Product Cart Billing

mysql mongo mysql mysql

Web Facade

Play 2.3 Scala 2.11 Spring-Boot 1.2.1 JPA/Hibernate

Spray 1.3 / Akka 2.3 Scala 2.10 ReactiveMongo

Scalatra Jetty …

finatra 1.6 async-mysql finagle 6.20 Dropwizard 0.7 JDBI

slide-10
SLIDE 10 1001

Challenges: ¡

10

  • Running:
  • How long does it take to get a dev system up

and running for a new team member?

  • How to run your ci system it in your favorite

cloud?

  • Configuring
  • Debugging
slide-11
SLIDE 11 1001

Case ¡Study: ¡Microzon-­‑Shop ¡

  • Start ¡system ¡with ¡docker ¡
  • Create ¡products ¡ ¡
  • Logstash ¡
  • Zipkin

11

DEMO

slide-12
SLIDE 12 1001

Why ¡is ¡that ¡a ¡challenge? ¡

12

Web Facade

Customer Product Cart Billing

mysql mongo mysql mysql

slide-13
SLIDE 13 1001

Why ¡is ¡that ¡a ¡challenge? ¡

13

Web Facade

Customer Product Cart Billing

mysql mongo mysql mysql

slide-14
SLIDE 14 1001

Why ¡is ¡that ¡a ¡challenge? ¡

14

Web Facade

Customer Product Cart Billing

mysql mongo mysql mysql

Support UI Marketing tool Reporting Payment adapter

slide-15
SLIDE 15 1001

Why ¡is ¡that ¡a ¡challenge? ¡

15

Web Facade

Customer Product Cart Billing

mysql mongo mysql mysql

Support UI Marketing tool Reporting Payment adapter

?

slide-16
SLIDE 16 100

Running/Configuring/Debugging

Takeaway

16

  • … ¡will ¡quickly ¡become ¡a ¡non-­‑trivial ¡maYer ¡
  • We ¡have ¡chosen ¡… ¡
  • docker ¡for ¡development ¡system ¡
  • puppet ¡for ¡»producIon« ¡
  • elas.csearch/logstash/kibana ¡for ¡distributed ¡

logging ¡

  • zipkin ¡for ¡request ¡tracing ¡
  • … ¡but ¡that ¡is ¡not ¡this ¡focus ¡of ¡this ¡talk
slide-17
SLIDE 17 1001

Challenge: ¡Deploying ¡

17

Zero-downtime deployment strategies/variants: Blue/Green, Wave, Canary,…

Service Version n+1 Service Version n Loadbalancer/ Router Delivery Pipeline Service Version n

Deploy

slide-18
SLIDE 18 1001

Challenge: ¡Service ¡discovery ¡

18

  • How to remove service nodes from the cluster or

take them temporary offline?

  • How to add new ones or take them online again?

How do services find each other? => ServiceDiscovery

slide-19
SLIDE 19 1001

Service ¡Discovery ¡by ¡configuraFon

You ¡(mis)use ¡your ¡configuraIon ¡management ¡tool ¡ (puppet/chef) ¡to ¡generate ¡service ¡configuraIon ¡with ¡ explicit ¡endpoints ¡

19

Config Management Node2 Node1 Node3

.................... .................... .................... .................... .................... ....................

update add/remove node entry

slide-20
SLIDE 20 1001

Service ¡Discovery ¡by ¡configuraFon

Pros: ¡

Simply ¡works ¡ No ¡extra ¡technology ¡involved ¡(and ¡thereby ¡no ¡extra ¡point ¡

  • f ¡failure) ¡

Cons: ¡

To ¡take ¡a ¡service ¡node ¡offline ¡one ¡has ¡to ¡update ¡all ¡of ¡its ¡ consumers ¡(or ¡wait ¡for ¡them ¡to ¡be ¡updated) ¡ All ¡consumers ¡have ¡to ¡be ¡able ¡to ¡reload ¡their ¡configuraIon ¡ without ¡restart ¡

20

slide-21
SLIDE 21 1001

Service ¡Discovery ¡by ¡DNS

DNS ¡is ¡actually ¡a ¡service ¡discovery

21

Customer Service Product Service2

DNS

Product Service1

10.X.X.1

Product Service3

10.X.X.2 10.X.X.3

{10.X.X.1,

10.X.X.2, 10.X.X.3} product.loc ?

slide-22
SLIDE 22 1001

DNS

Pros: ¡

Old ¡technology ¡that ¡is ¡proven ¡to ¡work ¡on ¡a ¡very ¡very ¡large ¡ scale ¡ Supported ¡by ¡almost ¡everyone ¡

Cons: ¡

Rather ¡crude ¡(and ¡very ¡inconvenient) ¡interface ¡(especially ¡ for ¡updates) ¡ Resolved ¡service ¡names ¡might ¡be ¡cached ¡on ¡mulIple ¡levels ¡ Focusses ¡purely ¡on ¡service ¡nodes, ¡not ¡on ¡the ¡services ¡itself

22

slide-23
SLIDE 23 1001

Also: ¡DNS ¡might ¡lead ¡to ¡wrong ¡assumpFons

23 public void connect( ... ) throws IOException { ... final InetAddress[] addresses = this.dnsResolver.resolve(host.getHostName()); ... for (int i = 0; i < addresses.length; i++) {
 final InetAddress address = addresses[i];
 final boolean last = i == addresses.length - 1;
 Socket sock = sf.createSocket(context);
 ... try { sock.setSoTimeout(socketConfig.getSoTimeout()); ...
 conn.bind(sock); return; } catch (final SocketTimeoutException ex) { ... } catch (final ConnectException ex) { ... } } }

Apache HttpClient 4.3:

  • rg.apache.http.impl.conn.HttpClientConnectionOperator
slide-24
SLIDE 24 1001

Service ¡discovery ¡service

Zookeeper ¡ Curator ¡ consul ¡ etcd ¡ doozerd ¡ SkyDNS ¡ Eureka ¡ …

24

Discovery Service Customer Product Cart Billing

slide-25
SLIDE 25 1001

EvaluaFon ¡criteria

  • ­‑ ¡High ¡availability ¡
  • ­‑ ¡Consistency ¡(consistency ¡over ¡availability?) ¡
  • ­‑ ¡Support ¡for ¡service-­‑level ¡checks ¡
  • ­‑ ¡API ¡(hYp, ¡DNS?, ¡…) ¡
  • ­‑ ¡Footprint ¡(Memory/CPU) ¡
  • ­‑ ¡MulIple ¡datacenter ¡support ¡
  • ­‑ ¡UI ¡
  • ­‑ ¡Template ¡engine ¡(for ¡config ¡files) ¡

25

slide-26
SLIDE 26 1001

Consul

26

Consul server cluster

consul server consul server consul server consul server consul server Raft consensus

service node A

consul agent service http / dns consul template (optional) config files write restart reload health check

service node A

consul agent service http / dns consul template (optional) config files write restart reload health check

slide-27
SLIDE 27 1001

Consul

27

Consul server cluster

consul server consul server consul server consul server consul server Raft consensus

service node A

consul agent service http / dns consul template (optional) config files write restart reload health check

service node A

consul agent service http / dns consul template (optional) config files write restart reload health check

slide-28
SLIDE 28 1001

Consul ¡

  • Show ¡consul ¡UI ¡
  • Show ¡web-­‑service ¡status ¡page ¡
  • Add ¡cart/remove ¡cart

28

DEMO

slide-29
SLIDE 29 1001

Challenge: ¡Resilience

29

Every ¡system ¡has ¡a ¡retry!

slide-30
SLIDE 30 1001

Do ¡not ¡do ¡failover/retry ¡on ¡connecFon ¡

GET ¡ok ¡ DELETE ¡ok ¡ PUT ¡ok ¡ POST ¡??? ¡

Duplicates ¡might ¡be ¡ok ¡(e.g. ¡create ¡new ¡shopping ¡cart) ¡ … ¡or ¡not ¡(e.g. ¡register ¡new ¡customer) ¡ might ¡be ¡solved ¡by ¡a ¡request ¡token ¡(e.g. ¡the ¡xsrf ¡token ¡ from ¡the ¡web) ¡as ¡long ¡as ¡the ¡service ¡supports ¡this ¡

GET ¡really ¡ok? ¡What ¡about ¡streaming?

30

slide-31
SLIDE 31 1001

Failover ¡should ¡be ¡part ¡of ¡the ¡business ¡

Usually ¡the ¡failover ¡strategy ¡depends ¡on ¡the ¡ concrete ¡use-­‑case ¡ Handling ¡failover ¡on ¡the ¡protocol ¡layer ¡(hYp-­‑client) ¡ might ¡hide ¡error ¡scenarios ¡from ¡the ¡programmer ¡ It ¡can ¡be ¡difficult ¡to ¡disInguish ¡between ¡technical ¡ and ¡business ¡error ¡on ¡the ¡protocol ¡layer ¡

As ¡a ¡rule ¡of ¡thumb: ¡You ¡want ¡to ¡retry ¡all ¡technical ¡error, ¡ but ¡not ¡the ¡business ¡errors ¡ … ¡though ¡even ¡that ¡is ¡discussable ¡in ¡some ¡cases

31

slide-32
SLIDE 32 1001

How ¡»not« ¡to ¡do ¡service ¡failover

32

public class ServiceFailover {
 private static final Random RANDOM = new Random(System.currentTimeMillis());
 
 public static <E, R> R retry(final List<E> endpoints, final Requester<E, R> requester) throws IOException {
 final int size = endpoints.size();
 
 if (size == 0) throw new RuntimeException("No active endpoints found");
 
 final int offset = RANDOM.nextInt(size);
 IOException lastException = null;
 
 for (int idx = 0; idx < size; idx++) {
 final E endpoint = endpoints.get((idx + offset) % size);
 
 try {
 return requester.performTry(endpoint);
 } catch (IOException e) {
 lastException = e;
 }
 }
 throw lastException;
 }
 
 @FunctionalInterface
 public interface Requester<E, R> {
 R performTry(E endpoint) throws IOException;
 }
 }

slide-33
SLIDE 33 1001

Resilience

33

  • Kill ¡2 ¡consul ¡nodes ¡
  • Kill ¡one ¡cart ¡node ¡
  • DEMO
slide-34
SLIDE 34 1001

Hystrix

Circuit-­‑Breaking ¡ Fail-­‑Early ¡ Developer’s ¡are ¡»forced« ¡to ¡think ¡in ¡commands ¡with ¡ potenIal ¡fallback ¡result ¡rather ¡than ¡REST-­‑calls

34

slide-35
SLIDE 35 1001

How ¡it ¡actually ¡should ¡look ¡like

35

Observe Service Timeout Request Draining Load Balancer Monitor Trace Observe Failure Accrual Request Timeout Pool Fail Fast Expiration Dispatcher

according to finagle

slide-36
SLIDE 36 1001

What ¡other ¡people ¡do

Nenlix ¡

Many ¡libraries ¡and ¡tools ¡that ¡build ¡up ¡on ¡top ¡of ¡each ¡other ¡ RxJava/ReacIveX: ¡ReacIve ¡extension/ReacIve ¡streaming ¡

Based ¡on ¡neYy: ¡RxNeYy ¡

Hystrix: ¡Basic ¡command ¡system ¡for ¡circuit-­‑breaking/fail-­‑ early ¡ Eureka: ¡Service ¡registry ¡ Ribbon: ¡REST-­‑Client ¡with ¡failover/service ¡discovery ¡based ¡

  • n ¡Hystrix/Eureka ¡

36

slide-37
SLIDE 37 1001

What ¡other ¡people ¡do

TwiYer ¡

Services ¡based ¡on ¡finagle ¡(scala) ¡

… ¡which ¡is ¡itself ¡based ¡on ¡neYy ¡ … ¡which ¡contains ¡als ¡the ¡basics ¡for ¡for ¡failover/retry/service-­‑ discovery/monitoring ¡

Service-­‑Discovery ¡done ¡via ¡zookeeper, ¡but ¡can ¡be ¡ adapted/extended ¡to ¡other ¡tools ¡ Several ¡frameworks/connectors ¡build ¡on ¡top: ¡finatra, ¡ async-­‑mysql-­‑connector ¡…

37

slide-38
SLIDE 38 100

Service ¡discovery

Takeaway

38

  • Helps ¡a ¡lot ¡to ¡realize ¡… ¡
  • … ¡any ¡kind ¡of ¡zero-­‑downIme ¡deployment ¡strategy ¡
  • … ¡a ¡self-­‑healing ¡micro-­‑service ¡jungle ¡
  • Does ¡not ¡create ¡a ¡fully ¡resilient ¡system ¡by ¡itself, ¡even ¡

though ¡it ¡is ¡the ¡basis ¡of ¡it ¡

  • Might ¡conflict ¡with ¡your ¡exisIng ¡configuraIon ¡

system ¡(when ¡creaIng ¡config ¡files ¡via ¡templates) ¡

  • Might ¡be ¡just ¡another ¡central ¡component ¡that ¡fails
slide-39
SLIDE 39 100

Failover/Retry

Takeaway

39

  • The ¡failover ¡strategy ¡usually ¡depends ¡on ¡the ¡

business ¡case ¡

  • A ¡full ¡failover ¡stack ¡is ¡quite ¡a ¡piece ¡of ¡work ¡
  • Emerging ¡frameworks ¡might ¡make ¡life ¡easier ¡or ¡at ¡

least ¡provide ¡a ¡reference ¡implementaIon