Slide 1

Slide 1 text

Smart Services & Smart Clients How microservices change the way you build and deploy code Frank Stratton
 Co-founder/CTO @FrankRStratton Runscope

Slide 2

Slide 2 text

Solve API Problems Fast Monitor, log, measure & share your API usage.

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

60 services 8 engineers

Slide 6

Slide 6 text

Why microservices?

Slide 7

Slide 7 text

0 000,000 000,000 000,000 000,000 000,000 May 2013 Sep Jan May Sep Jan 2015 Scaling the infrastructure Scaling the team

Slide 8

Slide 8 text

Microservices are highly independent

Slide 9

Slide 9 text

independent codebases independent deploys independent teams

Slide 10

Slide 10 text

There are a lot of moving parts…

Slide 11

Slide 11 text

If you don't invest in INFRASTRUCTURE don't invest in MICROSERVICES

Slide 12

Slide 12 text

Microservices = SOA + DevOps

Slide 13

Slide 13 text

Dashboard Identity get_teams()

Slide 14

Slide 14 text

Dashboard Identity get_teams() host001.runscope.com host002.runscope.com

Slide 15

Slide 15 text

import requests def get_teams(): url = “http://host002.runscope.com/teams” resp = requests.get(url) return resp.json() Dashboard Identity get_teams()

Slide 16

Slide 16 text

url = “http://host002.runscope.com/teams” url = “http://host003.runscope.com/teams” Dashboard Identity get_teams() X Identity

Slide 17

Slide 17 text

if ENVIRONMENT == “local”: url = “http://localhost:5000/teams” elif ENVIRONMENT == “test”: url = “http://test001.runscope.com/teams” elif ENVIRONMENT == “prod”: url = “http://host003.runscope.com/teams” Dashboard Identity get_teams()

Slide 18

Slide 18 text

How do you find a service?

Slide 19

Slide 19 text

How do you find a service? Smart Client

Slide 20

Slide 20 text

Smart Client import requests def get_teams(): url = “http://host001.runscope.com/teams” resp = requests.get(url) return resp.json()

Slide 21

Slide 21 text

Smart Client import smart_client def get_teams(): url = “http://host001.runscope.com/teams” resp = smart_client.get(url) return resp.json()

Slide 22

Slide 22 text

Smart Client import smart_client def get_teams(): url = “service://identity/teams” resp = smart_client.get(url) return resp.json()

Slide 23

Slide 23 text

Smart Client Service discovery service://identity/... Retry failed GET/PUT/DELETE (idempotent) requests Run HTTP requests asynchronously

Slide 24

Slide 24 text

Smart Client Atlas

Slide 25

Slide 25 text

Smart Client ZooKeeper Atlas DynamoDB /hosts/identity/host001.runscope.com = 5000 /hosts/identity/host001.runscope.com/enabled = True Register service metadata in Zookeeper & DynamoDB

Slide 26

Slide 26 text

Smart Client Atlas Sidecar Runs HAProxy on each host. Reads cluster state from atlas. Watches for changes to services and updates the local configuration. host001 host002 host003

Slide 27

Slide 27 text

Smart Client

Slide 28

Slide 28 text

Smart Client Service A Service A

Slide 29

Slide 29 text

Smart Client Service B Service B

Slide 30

Slide 30 text

Smart Client smart_client.get(“service://identity/teams”) requests.get(“http://localhost:4000/teams”, headers={“Runscope-Service”: “identity”})

Slide 31

Slide 31 text

haproxy.cfg frontend http-in bind *:4000 mode http acl host_api hdr(runscope-service) -i api acl host_billing hdr(runscope-service) -i billing acl host_mission-control hdr(runscope-service) -i mission-control acl host_elasticsearch hdr(runscope-service) -i elasticsearch use_backend api-backend if host_api use_backend billing-backend if host_billing use_backend mission-control-backend if host_mission-control use_backend elasticsearch-backend if host_elasticsearch

Slide 32

Slide 32 text

Smart Client smart_client.get(“service://identity/teams”) requests.get(“http://localhost:4000/teams”, headers={“Runscope-Service”: “identity”})

Slide 33

Slide 33 text

How do you find a service? Smart Client

Slide 34

Slide 34 text

How do you make building services easy?

Slide 35

Slide 35 text

How do you make building services easy? Smart Service

Slide 36

Slide 36 text

Smart Service

Slide 37

Slide 37 text

Smart Service Runscope/healthcheck

Slide 38

Slide 38 text

Smart Service bugsnag runscope-daemon alchemist smart-config

Slide 39

Slide 39 text

Smart Service Configuration Driven defaults.py REDIS_SERVICE = “redis-cluster-1” REDIS_DB = 2 BUGSNAG_API_KEY = “xyz123”

Slide 40

Slide 40 text

Smart Service Configuration Driven config = SmartConfig('example-service', defaults=example_service.defaults) app = SmartService('example-service', config=config)

Slide 41

Slide 41 text

Smart Service Various additions to the flask app object from flask import current_app current_app.realm current_app.redis current_app.database current_app.api

Slide 42

Slide 42 text

Smart Service Common Logging Configuration /var/log/runscope/.access.log /var/log/runscope/.error.log current_app.logger.warn(“Uh oh!”) bugsnag.notify(e)

Slide 43

Slide 43 text

$> generate-service my-awesome-service Creating a service skeleton with this configuration: Service name: my-awesome-service Destination directory: ~/runscope/my-awesome-service Python package name: my_awesome_service HTTP port: 5004 1. Generating files in ~/runscope/my-awesome-service 2. Initializing Git repository in ~/runscope/my-awesome-service 3. Creating virtualenv my-awesome-service 4. Installing Python prerequisites (requirements.txt and setup.py) All done! my-awesome-service source code can be found in ~/runscope/my-awesome-service Smart Service Auto Generate Service Skeletons

Slide 44

Slide 44 text

Smart Service Reduce Cognitive Overhead

Slide 45

Slide 45 text

How do you make building services easy? Smart Service

Slide 46

Slide 46 text

What happens when you have so many services?

Slide 47

Slide 47 text

What happens when you have so many services? A Lot :)

Slide 48

Slide 48 text

Automate everything

Slide 49

Slide 49 text

Language Agnostic

Slide 50

Slide 50 text

Language Agnostic HTTP is our common ‘language’

Slide 51

Slide 51 text

No shared databases

Slide 52

Slide 52 text

Dashboard Traffic Gateway API Postgresql

Slide 53

Slide 53 text

Dashboard Traffic Gateway API Postgresql X

Slide 54

Slide 54 text

Dashboard Traffic Gateway API Identity Postgresql Flask Redis A service owns it’s own datastore(s).

Slide 55

Slide 55 text

Dashboard Traffic Gateway API And exposes an API for that data. Identity GET /teams/ PUT /teams/ GET /buckets ...

Slide 56

Slide 56 text

Invest in deployment automation.

Slide 57

Slide 57 text

Invest in deployment automation. 1-Click Deploys

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

0 10 20 30 40 50 Jun 2014 Jul Aug Sep Oct Nov Dec Jan Feb Mar 2015 Deploys per day

Slide 60

Slide 60 text

Test & Monitor your APIs

Slide 61

Slide 61 text

Test Lifecycle Local Dev {{identity_host}} = http://localhost Local Agents

Slide 62

Slide 62 text

Test Lifecycle Test Realm Local Dev {{identity_host}} = http://test001.runscope.com Local Agents Trigger URLs

Slide 63

Slide 63 text

Test Lifecycle Test Realm Production Local Dev {{identity_host}} = http://host002.runscope.com Local Agents Trigger URLs Schedules

Slide 64

Slide 64 text

0 10 20 30 40 50 Jun 2014 Jul Aug Sep Oct Nov Dec Jan Feb Mar 2015 Deploys per day

Slide 65

Slide 65 text

Smart Services & Smart Clients How microservices change the way you build and deploy code Frank Stratton
 @FrankRStratton Runscope

Slide 66

Slide 66 text

Thanks! Frank Stratton
 @FrankRStratton Runscope

Slide 67

Slide 67 text

Thanks! p.s. - we’re hiring :) Frank Stratton
 @FrankRStratton Runscope https://www.runscope.com/jobs