FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices ....

35
From the Monolith to Microservices: Evolving Your Architecture to Scale Randy Shoup @randyshoup linkedin.com/in/randyshoup

Transcript of FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices ....

Page 1: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

From  the  Monolith  to  Microservices:      

Evolving  Your  Architecture  to  Scale Randy Shoup @randyshoup

linkedin.com/in/randyshoup

Page 2: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Background •  Consulting CTO at Randy Shoup Consulting

o  Helping companies from large enterprises to small startups scale their organizations and technology

o  “CTO as a service”

•  CTO at KIXEYE o  Real-time strategy games for web and mobile

•  Director of Engineering for Google App Engine o  World’s largest Platform-as-a-Service o  Part of Google Cloud Platform

•  Chief Engineer at eBay o  Multiple generations of eBay’s real-time search infrastructure

Page 3: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Architecture  Evolution

•  eBay

•  5th generation today •  Monolithic Perl à Monolithic C++ à Java à microservices

•  Twitter •  3rd generation today •  Monolithic Rails à JS / Rails / Scala à microservices

•  Amazon •  Nth generation today •  Monolithic C++ à Java / Scala à microservices

Page 4: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Evolution  to    Microservices

•  The Monolith

•  The Microservices Ecosystem

•  Migrating to Microservices

•  Life as a Service Owner

Page 5: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Evolution  to    Microservices

•  The Monolith

•  The Microservices Ecosystem

•  Migrating to Microservices

•  Life as a Service Owner

Page 6: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

The  Monolithic  Architecture

2-3 monolithic tiers

•  {JS, iOS, Android}

•  {PHP, Ruby, Python}

•  {MySQL, Mongo}

Presentation

Application

Database

Page 7: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

The  Monolithic  Application

Simple  at  first

In-­‐‑process  latencies

Single  codebase,  deploy  unit

Resource-­‐‑efficient  at  small  scale

Pros

Coordination  overhead  as  team  grows

Poor  enforcement  of  modularity

Poor  scaling  (vertical  only)

All-­‐‑or-­‐‑nothing  deploy  (downtime,  failures)

Long  build  times

Cons

Page 8: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

The  Monolithic    Database

Simple  at  first

Join  queries  are  easy

Single  schema,  deployment

Resource-­‐‑efficient  at  small  scale

Pros

Coupling  over  time

Poor  scaling  and  redundancy  (all-­‐‑or-­‐‑nothing,  vertical  only)

Difficult  to  tune  properly

All-­‐‑or-­‐‑nothing  schema  management

Cons

Page 9: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

“If  you  don’t  end  up  regreRing  your  early  technology  decisions,  you  probably  over-­‐‑engineered”

-- me

Page 10: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Evolution  to    Microservices

•  The Monolith

•  The Microservices Ecosystem

•  Migrating to Microservices

•  Life as a Service Owner

Page 11: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Microservices  

•  Single-purpose •  Simple, well-defined interface •  Modular and independent •  More graph of relationships than tiers •  Isolated persistence (!) •  *Not* a new idea

o  Nothing more than encapsulation and modularity A

C D E

B

Page 12: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Microservices  

Each  unit  is  simple

Independent  scaling  and  performance

Independent  testing  and  deployment

Can  optimally  tune  performance  (caching,  replication,  etc.)

Pros

Many  cooperating  units

Many  small  repos

Requires  more  sophisticated  tooling  and  dependency  management

Network  latencies

Cons

Page 13: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Ecosystem    of  Services

•  Hundreds to thousands of independent services

•  Many layers of dependencies, no strict tiers

•  Graph of relationships, not a hierarchy

C B

A E F

G D

Page 14: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Evolution,    not  Intelligent  Design

•  No centralized, top-down design of the system o  Most technology decisions made locally instead of globally o  Better decisions in the field

•  Variation and Natural selection o  Create / extract new services when needed to solve a problem o  Deprecate services when no longer used o  Services justify their existence through usage

•  Appearance of clean layering is an emergent property

Page 15: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Google    Service  Layering

•  Cloud Datastore: NoSQL service o  Highly scalable and resilient o  Strong transactional consistency o  SQL-like rich query capabilities

•  Megastore: geo-scale structured database o  Multi-row transactions o  Synchronous cross-datacenter replication

•  Bigtable: cluster-level structured storage o  (row, column, timestamp) -> cell contents

•  Colossus: next-generation clustered file system o  Block distribution and replication

•  Borg: cluster management infrastructure o  Task scheduling, machine assignment

Cloud  Datastore

Megastore

Bigtable

Colossus

Borg

Page 16: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Standardization •  Standardized communication

o  Network protocols o  Data formats o  Interface schema / specification

•  Standardized infrastructure o  Source control o  Configuration management o  Cluster management o  Monitoring, alerting, diagnosing, etc.

Page 17: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Standards become standards by being better than the alternatives!

Page 18: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

“Enforcing”  Standardization

•  Encouraged via

o  Libraries o  Support in underlying services o  Code reviews o  Searchable code

Page 19: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

KIXEYE    Service  Chassis •  Goal: Make it easy to build and deploy Microservices

•  Chassis core •  Configuration integration •  Registration and Discovery •  Monitoring and Metrics •  Load-balancing for downstream services •  Failure management for downstream services

•  Development / Deployment Pipeline •  Transport layer over REST / JSON or WebSockets •  Service template in Maven •  Build pipeline through Puppet -> Packer -> AMI •  Red-black deployment via Asgard

Page 20: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

KIXEYE    Service  Chassis •  Heavy use of NetflixOSS

•  Asgard •  Hystrix •  Ribbon + WebSockets è Janus •  Eureka

è  Results •  15 minutes from no code to running service in AWS (!) •  Open-sourced at https://github.com/Kixeye

Page 21: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

The easiest way to encourage best practices is with *code*!

Page 22: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Make it really easy to do the right thing, and harder to do the wrong thing!

Page 23: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Evolution  to    Microservices

•  The Monolith

•  The Microservices Ecosystem

•  Migrating to Microservices

•  Life as a Service Owner

Page 24: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Migrating    Incrementally

•  Find your worst scaling bottleneck

•  Wall it off behind an interface

•  Replace the implementation

•  è Rinse and Repeat

Page 25: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Building    Microservices

•  Common Chassis / Framework o  Make it trivially easy to build and maintain a service

•  Define Service Interface (Formally!) o  Propose o  Discuss with client(s) o  Agree

•  Prototype Implementation o  Simplest thing that could possibly work o  Client can integrate with prototype o  Implementor can learn what works and what does not

Page 26: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Building    Microservices

•  Real Implementation o  Throw away the prototype (!)

•  è Rinse and Repeat

Page 27: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Service  Anti-­‐‑PaRerns

•  The “Mega-Service” o  Overbroad area of responsibility is difficult to reason about, change o  Leads to more upstream / downstream dependencies

•  Shared persistence o  Breaks encapsulation, encourages “backdoor” interface violations o  Unhealthy and near-invisible coupling of services o  (-) Initial eBay SOA efforts

Page 28: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Evolution  to    Microservices

•  The Monolith

•  The Microservices Ecosystem

•  Migrating to Microservices

•  Life as a Service Owner

Page 29: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Goals  of  a    Service  Owner

•  Meet the needs of my clients … •  Functionality •  Quality •  Performance •  Stability and reliability •  Constant improvement over time

•  … at minimum cost and effort •  Leverage common tools and infrastructure •  Leverage other services •  Automate building, deploying, and operating my service •  Optimize for efficient use of resources

Page 30: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Responsibilities  of  a  Service  Owner

•  End-to-end Ownership o  Team owns service from design to deployment to retirement o  No separate maintenance or sustaining engineering team o  DevOps philosophy of “You build it, you run it”

•  Autonomy and Accountability

o  Freedom to choose technology, methodology, working environment o  Responsibility for the results of those choices

Page 31: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Service  as    Bounded  Context

•  Primary focus on my service o  Clients which depend on my service o  Services which my service depends on o  Cognitive load is very bounded

•  Very little worry about

o  The complete ecosystem o  The underlying infrastructure

•  è Small, nimble service teams

Service

Client  A

Client  B

Client  C

Page 32: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Microservice  Relationships

•  Vendor – Customer Relationship o  Friendly and cooperative, but structured o  Clear ownership and division of responsibility o  Customer can choose to use service or not (!)

•  Service-Level Agreement (SLA) o  Promise of service levels by the provider o  Customer needs to be able to rely on the service, like a utility

•  Charging and Cost Allocation o  Charge customers for *usage* of the service o  Aligns economic incentives of customer and provider o  Motivates both sides to optimize

Page 33: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Maintaining    Interface  Stability

•  Backward / forward compatibility of interfaces

o  Can *never* break your clients’ code o  Often multiple interface versions o  Sometimes multiple deployments

o  Majority of changes don’t impact the interface in any way

•  Explicit deprecation policy o  Strong incentive to wean customers off old versions (!)

Page 34: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Recap:    Evolution  to    Microservices

•  The Monolith

•  The Microservices Ecosystem

•  Migrating to Microservices

•  Life as a Service Owner

Page 35: FromtheMonolithto% Microservices: … · 2015-05-27 · Java / Scala ! microservices . Evolutionto%% Microservices8 • The Monolith • The Microservices Ecosystem • Migrating

Obrigado! •  @randyshoup

•  linkedin.com/in/randyshoup

•  Slides will be at slideshare.net/randyshoup