effective microservices in a data-centric world ?· • best for high cardinality a and high...

Download Effective Microservices in a Data-centric World ?· • Best for high cardinality A and high cardinality…

Post on 07-Sep-2018

212 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Effective Microservicesin a Data-centric World

    Randy Shoup @randyshoup

    linkedin.com/in/randyshoup

  • Background VP Engineering at Stitch Fix

    o Revolutionizing retail by combining Art and Science

    Consulting CTO as a serviceo Helping companies scale their organizations and technology

    Director of Engineering for Google App Engineo Worlds largest Platform-as-a-Service

    Chief Engineer at eBayo Multiple generations of eBays infrastructure

  • Stitch Fix

  • Stitch Fix

  • Stitch Fix

  • Stitch Fix

  • Combining Art and [Data] Science

    1:1 Ratio of Data Science to Engineeringo >70 software engineerso >70 data scientists and algorithm developerso Unique in our industry?

    Apply intelligence to *every* part of the businesso Buyingo Inventory managemento Logistics optimizationo Styling recommendationso Demand prediction

    Humans and machines augmenting each other

  • Styling at Stitch Fix

    Personal styling

    Inventory

  • PersonalizedRecommendations

    Inventory Algorithmic recommendations

    Machine learning

  • Expert HumanCuration

    Human curation

    Algorithmic recommendations

  • How do we work, and why does it work?

  • Modern SoftwareDevelopment

    Practices

    CultureTechnology

    Organization

  • Modern SoftwareDevelopment

    TDD and Continuous

    Delivery

    DevOpsMicroservices

    Small Teams

  • Modern SoftwareDevelopment

    TDD and Continuous

    Delivery

    DevOpsMicroservices

    Small Teams

  • SmallService Teams

    Teams Aligned to Domainso Clear, well-defined area of responsibilityo Single service or set of related services

    Cross-functional Teamso Team has inside it all skill sets needed to do the job

    Depend on other teams for supporting services, libraries, and tools

  • Modern SoftwareDevelopment

    TDD and Continuous

    Delivery

    DevOpsMicroservices

    Small Teams

  • Test-Driven Development

    Tests help you go fastero Tests have your backo Development velocity

    Tests make better codeo Confidence to break thingso Confidence to refactor

    Tests make better systemso Catch bugs earlier, fail faster

  • Test-Driven Development

    Dont have time to do it right ?o WRONG J Dont have time to do it twice (!)

    Do it right (enough) the first timeo The more constrained you are on time and resources, the more important

    it is to build solid featureso Right != perfect

    Basically no bug tracking system (!)o Bugs are fixed as they come upo Backlog contains features we want to buildo Backlog contains technical debt we want to repay

  • ContinuousDelivery

    Most applications deployed multiple times per day

    More solid systemso Release smaller units of worko Faster to repair, easier to diagnoseo Smaller changes to roll back or roll forward

    Enables experimentationo Small experiments and rapid iteration are cheap

  • Modern SoftwareDevelopment

    TDD and Continuous

    Delivery

    DevOpsMicroservices

    Small Teams

  • DevOps End-to-end Ownership

    o Team owns service from design to deployment to retirement

    Responsible for o Featureso Qualityo Performanceo Operationso Maintenance

    You build it, you run it!

  • Modern SoftwareDevelopment

    TDD and Continuous

    Delivery

    DevOpsMicroservices

    Small Teams

  • 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 Perl / C++ Java / Scala microservices

  • Microservices

    Single-purpose Simple, well-defined interface Modular and independent

    A

    C D E

    B

  • Microservices are nothing more than SOA done properly.

    -- me

  • Microservices

    Single-purpose Simple, well-defined interface Modular and independent Isolated persistence (!)

    A

    C D E

    B

  • MicroservicePersistence

    Approach 1: Operate your own data storeo Store to your own instance(s) of {Postgres, MySQL, etc.}, owned and

    operated by the service team

    Approach 2: Use a persistence serviceo Store to your own table(s) in {Dynamo, RDS, Spanner, etc.}, operated as a

    service by another team or by a third-party providero Isolated from all other users of the service

    Only external access to data store is through published service interface

  • Maintaining Interface Stability

    Backward / forward compatibility of interfaceso Can *never* break your clients code

    Semantic versioning (major.minor.patch)o Often multiple interface versionso Sometimes multiple deployments

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

  • Extracting Microservices

    Problem: Monolithic shared DB

    Clients Shipments Items Styles, SKUs Warehouses etc.

    stitchfix.com Styling app Warehouse app Merch app

    CS app Logistics app Payments service Profile service

  • Extracting Microservices

    Decouple applications / services from shared DB

    Clients Shipments Items Styles, SKUs Warehouses etc.

    stitchfix.com Styling app Warehouse app Merch app

    CS app Logistics app Payments service Profile service

  • Extracting Microservices

    Decouple applications / services from shared DB

    Styling app Warehouse app

    core_item

    core_sku

    core_client

  • Extracting Microservices

    Step 1: Create a service

    Styling app Warehouse app

    core_item

    core_sku

    core_client

    client-service

  • Extracting Microservices

    Step 2: Applications use the service

    Styling app Warehouse app

    core_item

    core_sku

    core_client

    client-service

  • Extracting Microservices

    Step 3: Move data to private database

    Styling app Warehouse app

    core_item

    core_sku

    client-service

    core_client

  • Extracting Microservices

    Step 4: Rinse and Repeat

    Styling app Warehouse app

    core_sku

    client-service

    core_client

    item-service

    core_item

  • Extracting Microservices

    Step 4: Rinse and Repeat

    Styling app Warehouse app

    client-service

    core_client

    item-service

    core_item

    style-service

    core_sku

  • Extracting Microservices

    Step 4: Rinse and Repeat

    Styling app Warehouse app

    client-service

    core_client

    item-service

    core_item

    style-service

    core_sku

  • Microservice Techniques:Shared Data

    Problemo Monolithic database makes it easy to leverage shared datao Where does shared data go in a microservices world?

    Principle: Single System of Recordo Every piece of data is owned by a single serviceo That service represents its canonical system of recordo Every other copy of that data is a read-only, non-authoritative cache

  • Microservice Techniques:Shared Data

    Approach 1: Synchronous Lookupo Customer service owns customer datao Order service calls customer service in real time

    order-service

    customer-service

  • Microservice Techniques:Shared Data

    Approach 2: Async event + local cacheo Customer service owns customer datao Customer service sends customer-updated event when customer

    changeso Order service caches current customer information

    order-servicecustomer-service

  • Microservice Techniques:Shared Data

    Approach 3: Shared metadata library o Read-only metadata, basically immutableo E.g., size schemas, colors, fabrics, US States, etc.

    receiving-serviceitem-service

    style-service

  • Events asFirst-Class Construct

    A significant change in stateo Statement that some interesting thing occurredo 0 | 1 | N consumers subscribe to the event, typically asynchronously

    Fourth fundamental building blocko Presentation interface / interactiono Application stateless business logico Persistence databaseo State changes events

    Events represent how the real world workso Finance, software development process, any workflow

  • Microservicesand Events

    Events are a first-class part of the interface

    A service interface includeso Synchronous request-response (REST, gRPC, etc)o Events the service produceso Events the service consumeso Bulk reads and writes (ETL)

    The interface includes any mechanism for getting data in or out of the service (!)

  • Microservice Techniques:Joins

    Problemo Monolithic database makes joins very easyo Splitting the data into separate services makes joins very hard

  • Microservice Techniques:Joins

    Approach 1: Service that Materializes the Viewo Listen to events from item-service, events from order-serviceo Maintain denormalized join of items and orders together in local storage

    Best for high cardinality A and high cardinality B (M:N join)

    Items Orders

    item-feedback-serviceitem-serviceorder-service

  • Microservice Techniques:Joins

    Many common systems do thiso Most NoSQL approacheso Materialized view in database systemso Search engineso Analytic systemso Log aggregators

  • Microservice Techniques:Joins

    Approach 2: Join in Application / Cliento Get a single customer from customer-serviceo Query matching orders for that customer from order-service

    Best for single A, mu