+ All Categories
Home > Documents > Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way...

Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way...

Date post: 02-Jun-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
59
Design Micro Service Architectures the Right Way Michael Bryzek [email protected] / @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO Gilt
Transcript
Page 1: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Design Micro Service Architectures the

Right Way

Michael [email protected] / @mbryzek

Cofounder / CTO Flow

Cofounder / ex-CTO Gilt

Page 2: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

A personal story

Could you change this URL from

https://foo.com/latest/bar.js to

https://foo.com/1.5.3/ bar.js ?

è Sorry – that would take weeks; we don’t have the resources to do that.

Page 3: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

https://www.pinterest.com/pin/262264378280617506/

It’s just a friggin URL!!!

Page 4: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

How does this happen?

• URL in a library• 100s of services to update• Some not touched in years,

requiring dependency updates

https://www.pinterest.com/pin/262264378280617506/

Page 5: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Great Architecture

Scales Development Teams

Delivers Quality

Enables High Performance / Low Cost

Supports Future Features Naturally

Page 6: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Not So Great Architecture

Tradeoffs:

http://ziogeek.com/wp-content/uploads/2013/07/spaghetti.jpg

Near term velocity

Future Paralysis

Page 7: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Design Micro Service Architectures the Right Way

Page 8: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

About Me

www.flow.io

www.gilt.com

Page 9: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Let’s Start

With a few

Misconceptions

Page 10: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Misconception #1

Micro Services enable our teams to choose the best

programming languages and frameworks for their tasks

Reality:We’ll demonstrate just how expensive this is.

Team size and investment are critical inputs.

Page 11: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Misconception #2

Code Generation is Evil

Reality:

What’s important is creating a defined

schema that is 100% trusted.

We’ll demonstrate one technique leveraging code generation

Page 12: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Misconception #3

The Event Log Must be the Source of Truth

Reality:

Events are critical parts of an interface.

But it’s okay for services to be the

system of record for their resources.

Page 13: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Misconception #4

Developers can maintain no more than 3 services each

Reality:

Wrong metric; we’ll demonstrate where automation shines.

Flow developers today each maintain ~5 services

Weekly maintenance <5% of time

Page 14: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Flow Commerce ArchitectureFlow Platform Architecture

Exte

rnal

Dat

a Pro

vider

s (e

.g.,

FX, I

P Ge

o, II

N/BI

N, e

tc.)

Catalog Payment Inventory Orders 100+ services

Event Bus (Kinesis)

Lambda Architecture / Data Mart

API Proxy

OMS

3PL / WMS, Etc.

EcommercePlatform

RetailWebsite

FLOW APIs

Flow

.js

Flow Console Track.flow.ioM

icro

serv

ices

Integration Methods & Services

Client Platform

Fulfillment

Shopify Magento

SFCC Solidus

Plugins & Cartridges

Direct Integrations

Checkout UI

Flow SystemClient System3rd Party DataData Flow

Key

FTP Webhook

Kinesis Partner API

Amazon Web Services

Client Checkout

Page 15: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

API Definition Done correctly, even things likeGDPR compliance can be modeled

Page 16: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Resource Oriented

Page 17: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Definitions in Git, with Continuous Integration

Page 18: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Tests Enforce Consistency

Goal: It should feel like one person wrote the entire API

Page 19: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Tests Prevent Errors

https://app.apibuilder.io/history?org=flow&app=api

Verify potentially breaking changesduring API Design Phase

Page 20: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

API Implementation Supported by Code Generation

Page 21: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Code Generation: Routes

Guarantee that API operations are actually defined

User friendly paths

Consistent naming for methods

Page 22: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Code Generation: Client

Page 23: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Code Generation: Mock Client

Mock and Client from Same Source

Enables High Fidelity, Fast Testing

Page 24: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Code Generation: Clients

The system of record IS the API specification

Code generation ensures that we actually adhere to the spec

Provide many common languages for our users

[https://app.apibuilder.io/generators/]

Page 25: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Now Let’s Implement

Goal: Code we actually write is simple, consistent

Page 26: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Database Architecture

Each micro service application owns its database

No other service is allowed to connect to the database

Other services use only the service interface (API + Events)

Page 27: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Create a DatabaseCLI as single interface for infra and common development tasks

Page 28: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Define storage requirements in metadata

Describe ”scala” requirements

Describe “psql” requirements

Code generate the table definition

Code generate the Data Access Object

Note data tier independent from API,

Just uses same toolchain

Page 29: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Code generation: Create a Table

Consistent checks, metadata

Enable global features like ‘hash_code’ to minimize writes

Page 30: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Code generation: Scala Class

Normalize access to DB

Ensure proper indexes exist from start

Page 31: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Automated Tests

Use the generated mock client

Page 32: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Test Resource Operations

Use the generated mock clients to write simple tests

Page 33: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Time to Deploy

Page 34: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Continuous Delivery

“Continuous Delivery is a

prerequisite to managing micro

service architectures”

--@mbryzek

Page 35: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Continuous Delivery

Deploy triggered by a git tag

Git tags created automatically by a change on master (e.g. merge PR)

100% automated, 100% reliable

Page 36: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Continuous Delivery is Critical

https://github.com/flowcommerce/delta

Page 37: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Auto Deploy on New Commit on Master

Page 38: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Microservice Infrastructure – keep it simple

Page 39: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Standard Health Checks

Page 40: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Events

Page 41: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

“We have an amazing API, but

please subscribe to our event

streams instead.”

Page 42: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Principles of an Event Interface

First class schema for all events

Producers guarantee at least once delivery

Consumers implement idempotency

Flow:

- End to end single event latency ~ 500 ms

- Based on postgresql – scaled to ~1B events / day / service

Page 43: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Events: Approach

Producers:• Create a journal of ALL operations on table

• Record operation (insert, update, delete)

• On creation, queue the journal record to be published

• Real time, async, we publish 1 event per journal record

• Enable replay by simply requeuing journal record

Page 44: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Events: Approach

Consumers:• Store new events in local database, partitioned for fast removal

• On event arrival, queue record to be consumed

• Process incoming events in micro batches (by default every 250ms)

• Record failures locally

Page 45: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Events: Schema First

1 model / event

N events in one union type

1 union type / stream

Stream owned by 1 service

Most services define exactly 1 stream

Page 46: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Events: Schema Linter

Page 47: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Producers: Database Journal

Document retention period

Code generate journal

Use partitions to manage storage

https://github.com/gilt/db-journaling

Page 48: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Producers: Streams

Reflection used to generate stream name

io.flow.v0.user_event.json

Page 49: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Producing an Event

Note the UserVersion class which is also code generated.

Guarantees that all code in all services looks the same.

Page 50: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Producers: Testing

Page 51: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Consumers: Processing Incoming Events

Page 52: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Consumers: Testing

Factories classes generated from the API Spec

Page 53: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Dependencies

Keeping things up to date

Page 54: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Dependencies

Goal: Automatically update all services to latest dependencies• Critical for security patches / bug fixes in core libraries

• Takes hours (not weeks or months)

• Same process for internally developed libraries and open source

• Flow: we upgrade all services every week to latest dependencies

Page 55: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Dependencies: Tracking

https://dependency.flow.io/

https://github.com/flowcommerce/dependency

Page 56: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Dependencies: Updating

Page 57: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Dependencies & Continuous Delivery

Deploy Once the Build Passes

Page 58: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Summary: Critical Decisions

Design schema first for all APIs and Events– consume events (not API) by default

Invest in automation – deployment, code generation, dependency management

Enable teams to write amazing and simple tests– drives quality, streamlines maintenance, enables continuous delivery

Page 59: Design Micro Service Architectures the Right Way...Design Micro Service Architectures the Right Way Michael Bryzek mike@flow.io/ @mbryzek Cofounder / CTO Flow Cofounder / ex-CTO GiltHow

Thank You!Go forth and Design Micro Service Architectures the Right Way

Michael [email protected] / @mbryzek

Cofounder / CTO Flow

Cofounder / ex-CTO Gilt

We’re hiring: https://www.flow.io/careers


Recommended