smart services & smart clients - how microservices change the way you build and deploy code

65
Smart Services & Smart Clients How microservices change the way you build and deploy code Neil Mansilla Developer Relations @mansillaDEV Runscope Presented at YAPC 2015 Salt Lake City

Upload: neil-mansilla

Post on 06-Aug-2015

169 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Services & Smart Clients

How microservices change the way you build and deploy code

Neil Mansilla Developer Relations @mansillaDEV

Runscope

Presented at YAPC 2015Salt Lake City

Page 2: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Solve API Problems FastMonitor, log, measure & share your API usage.

Page 3: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code
Page 4: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code
Page 5: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

65 services 9 engineers

Page 6: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Why microservices?

Page 7: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

0

14,000,000

28,000,000

42,000,000

56,000,000

70,000,000

May 2013 Sep Jan May Sep Jan 2015

Scaling the infrastructure

Scaling the team

Page 8: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Microservices are highly independent

Page 9: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

independent codebases independent deploys independent teams

Page 10: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

There are a lot of moving parts…

Page 11: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

If you don't invest in INFRASTRUCTURE

don't invest in MICROSERVICES

Page 12: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Microservices = SOA + DevOps

Page 13: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Dashboard Identity

get_teams()

Page 14: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Dashboard Identity

get_teams()

host001.runscope.com host002.runscope.com

Page 15: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

import requests

def get_teams(): url = “http://host002.runscope.com/teams” resp = requests.get(url)

return resp.json()

Dashboard Identity

get_teams()

Page 16: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

url = “http://host002.runscope.com/teams”url = “http://host003.runscope.com/teams”

Dashboard Identity

get_teams() XIdentity

Page 17: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

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()

Page 18: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

How do you find a service?

Page 19: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

How do you find a service?

Smart Client

Page 20: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Clientimport requests

def get_teams(): url = “http://host001.runscope.com/teams”

resp = requests.get(url)

return resp.json()

Page 21: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Clientimport smart_client

def get_teams(): url = “http://host001.runscope.com/teams”

resp = smart_client.get(url)

return resp.json()

Page 22: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Clientimport smart_client

def get_teams(): url = “service://identity/teams”

resp = smart_client.get(url)

return resp.json()

Page 23: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart ClientService discovery

service://identity/...

Retry failed GET/PUT/DELETE (idempotent) requests

Run HTTP requests asynchronously

Page 24: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Client

Atlas

Page 25: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Client

ZooKeeper

Atlas

DynamoDB

/hosts/identity/host001.runscope.com = 5000/hosts/identity/host001.runscope.com/enabled = True

Register service metadata in Zookeeper & DynamoDB

Page 26: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

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

Page 27: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Client

Page 28: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Client

Service AService A

Page 29: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart ClientService B

Service B

Page 30: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Clientsmart_client.get(“service://identity/teams”)

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

Page 31: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

haproxy.cfgfrontend 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

Page 32: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Clientsmart_client.get(“service://identity/teams”)

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

Page 33: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

How do you find a service?

Smart Client

Page 34: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

How do you make building services easy?

Page 35: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

How do you make building services easy?

Smart Service

Page 36: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Service

Page 37: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Service

Runscope/healthcheck

Page 38: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Service

bugsnag runscope-daemon alchemist smart-config

Page 39: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Service

Configuration Driven

defaults.py

REDIS_SERVICE = “redis-cluster-1”REDIS_DB = 2

BUGSNAG_API_KEY = “xyz123”

Page 40: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Service

Configuration Driven

config = SmartConfig('example-service', defaults=example_service.defaults)

app = SmartService('example-service', config=config)

Page 41: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Service

Various additions to the flask app object

from flask import current_app

current_app.realmcurrent_app.rediscurrent_app.databasecurrent_app.api

Page 42: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Service

Common Logging Configuration

/var/log/runscope/<service>.access.log/var/log/runscope/<service>.error.log

current_app.logger.warn(“Uh oh!”)bugsnag.notify(e)

Page 43: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

$> 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-service2. Initializing Git repository in ~/runscope/my-awesome-service3. Creating virtualenv my-awesome-service4. Installing Python prerequisites (requirements.txt and setup.py)

All done! my-awesome-service source code can be found in ~/runscope/my-awesome-service

Smart ServiceAuto Generate Service Skeletons

Page 44: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Smart Service

Reduce Cognitive Overhead

Page 45: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

How do you make building services easy?

Smart Service

Page 46: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

What happens when you have so many services?

Page 47: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

What happens when you have so many services?

A Lot :)

Page 48: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Automate everything

Page 49: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Language Agnostic

Page 50: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Language AgnosticHTTP is our common ‘language’

Page 51: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

No shared databases

Page 52: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

DashboardTraffic

GatewayAPI

Postgresql

Page 53: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

DashboardTraffic

GatewayAPI

PostgresqlX

Page 54: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

DashboardTraffic

GatewayAPI

Identity

Postgresql

Flask

Redis

A service owns it’s own datastore(s).

Page 55: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

DashboardTraffic

GatewayAPI

And exposes an API for that data.

Identity

GET /teams/<id>

PUT /teams/<id>

GET /buckets

...

Page 56: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Make Deploying Code Really Easy

Page 57: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Make Deploying Code Really Easy

1-Click Deploys

Page 58: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code
Page 59: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

0

10

20

30

40

50

Jun 2014 Jul Aug Sep Oct Nov Dec Jan Feb Mar 2015

Deploys per day

Page 60: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Test & Monitor your APIs

Page 61: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Test Lifecycle

Local Dev{{identity_host}} = http://localhost

Local Agents

Page 62: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Test Lifecycle

Test Realm

Local Dev

{{identity_host}} = http://test001.runscope.com

Local Agents

Trigger URLs

Page 63: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Test Lifecycle

Test Realm

Production

Local Dev

{{identity_host}} = http://host002.runscope.com

Local Agents

Trigger URLs

Schedules

Page 64: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

0

10

20

30

40

50

Jun 2014 Jul Aug Sep Oct Nov Dec Jan Feb Mar 2015

Deploys per day

Page 65: Smart Services & Smart Clients - How Microservices Change the Way You Build and Deploy Code

Thanks!

p.s. - we’re hiring :)

Runscope

https://www.runscope.com/jobs

Neil Mansilla@mansillaDEV