the art of decomposing monoliths - kfir bloch - codemotion amsterdam 2016

58
Kfir Bloch The Art of Decomposing Monoliths Head of Backend Engineering @ Wix @kfirondev To microservice or not to microservice

Upload: codemotion

Post on 16-Apr-2017

274 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Kfir Bloch

The Art of Decomposing Monoliths

Head of Backend Engineering @ Wix @kfirondev

To microservice or not to microservice

Page 2: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Kfir Bloch

Your pic here

• Head of backend engineering @ Wix

• 17 years experience as hands-on developer

• Joined Wix almost 6 years agolinkedin/in/blochkfir github.com/kfiron@[email protected]

Page 3: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016
Page 4: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016
Page 5: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Wix in NumbersOver

72M users (website builders)

Static storage is >2PB of Data

3 data centers + 3 clouds

(Google, Amazon, Azure)

2B HTTP requests/day

~1,000 people work at Wix

@kfirondev

Page 6: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Wix and MicroservicesIn the past 3 years we migrated to a Microservices architecture. It helps us:

• Scale our software

• Scale our people

• Meet product and marketing life cycle

• Embrace ownership and maintain a “startup-ish” culture

~200different services

@kfirondev

Page 7: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

@kfirondev

Page 8: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Microservices is the new black

@kfirondev

Page 9: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

In computing, microservices is a software architecture style in which complex applications are composed of small, independent processes communicating with each other using language-agnostic APIs.

These services are small, highly decoupled and focus on doing a small task, facilitating a modular approach to system-building.

@kfirondev

Page 10: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Microservices characteristics

Protocol

Circuit Breaker

SOA

ServiceDiscovery

CascadingFailure

ReplaceableUnits

ServiceGraph

ScalableUnits

Documentation

www.maplecityrubber.com@kfirondev

Page 11: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

But I will talk about:

When (and when NOT) to decompose your monolith

@kfirondev

Page 12: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Why do you think it is important to know when to decompose?

@kfirondev

Sometimes less is more

Page 13: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Microservices have trade-offs

@kfirondev

Page 14: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Each I/O hop is a failure point

Partial deployment

Strong interfaces between services are harder to refactor

Ops complexityEnd-to-end testing is challenging

@kfirondev

Page 15: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Mitigations● I/O hops are failure points

○ Proper HTTP configurations (timeouts, async, etc.)○ Retry mechanism○ Idempotent API○ Circuit breakers○ Monitoring○ Eventual consistency when needed

@kfirondev

Page 16: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Mitigations● Partial deployment

○ Feature toggle mechanism

@kfirondev

Page 17: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Mitigations● Ops complexity

○ Automation○ Developers own the Ops

@kfirondev

Page 18: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Mitigations● Strong interface – hard to refactor

○ Backward / forward compatibility○ Strong build system - dependency○ Proper contact tests

@kfirondev

Page 19: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

There is no way to avoid the additional riskAnother service == Another failure point

@kfirondev

Page 20: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Once we accept our limits, we go beyond them.

- Albert Einstein

@kfirondev

Page 21: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

To microserviceor not to microservice?

@kfirondev

Page 22: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Decompose to gain resource isolation for high availability

01

Page 23: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

File UploadClient Web File

Storage

Items (CRUD) Items DBItems Catalog

Service

Network problem

@kfirondev

Server threads are busy on I/O

Server cannot accept any

more requests

Client cannot perform critical

missions like deleting an

item

Page 24: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Different APIs have different SLAs● Some are near real time & some are not● Some are eventually consistent● Some are not critical and can fail● Some should respond within X ms

@kfirondev

Page 25: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Decompose to avoid competition on shared resources

@kfirondev

Page 26: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

File UploadClient Web File

Storage

Items (CRUD) Items DBItems Catalog

Service

@kfirondev

Page 27: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

File UploadClient Web File

Storage

Items (CRUD) Items DB

Items Service

Files Service

@kfirondev

Page 28: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Decompose by different life cycles

02

Page 29: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

4 PM Deploy – Items catalog feature

BI Storage

Items (CRUD) Items DBItems Catalog

ServiceCoupons

@kfirondev

5 PM Deploy – Coupon feature6 PM Deploy – Coupon feature9 PM Deploy – Coupon feature12 AM Rollback – Due to bug in items catalog

THE COMPANY LOSES MONEY

Page 30: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Items (CRUD) Items DBItems Catalog

ServiceCoupons

@kfirondev

B1 Storage

Page 31: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

B1 Storage

Items (CRUD) Items DB

Coupons Service

Items Catalog Service

@kfirondev

Page 32: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

03Decompose to reuse and share logic

Page 33: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Google

Items DBItems Catalog

ServiceGeo

Geo (3rd party)

Geo DB

Geo

User Management Service

Geo

User DB

Items DB

Geo

User Management Service

User DB

@kfirondev

Page 34: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Google

Items DBItems Catalog

Service

Geo (3rd party)

Geo DB

Geo

User Management Service

User DB

Geo ServiceFetch GeoFetch Geo

@kfirondev

Page 35: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Google

Items DBItems Catalog

ServiceGeo

Geo (3rd party)

Geo DB

Geo

User Management Service

Geo

User DB

@kfirondev

WILL FAIL AT SOME POINT

Common mistake to avoid

Page 36: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Each service must have its own DB

@kfirondev

Page 37: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

DBService A

An example when not to decompose

Extract Cookie Info

DBService B

Extract Cookie Info

@kfirondev

Page 38: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Microservices are deployable artifacts that have Ops or I/O dependencies

@kfirondev

Page 39: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Tested code that is CPU-bound is more secure and consistent

@kfirondev

Page 40: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

04Decompose to have single team responsibility

Page 41: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Did you know that 90% of R&D projects fail?

○ Because of content○ Because of bugs○ Because of time to market

Do you know how to reduce it to 70%?

○ 3-5 developers on 1 team○ 3-5 months per project

@kfirondev

Page 42: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

@kfirondev

Decompose to support organization scalability

Page 43: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Large teams cannot efficiently handle a large code base

@kfirondev

Small teams embrace responsibility and accountability

Page 44: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.

@kfirondev

Conway’s law

Page 45: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Decomposition helps your culture remain startup-ish when your size is corporate-ish

@kfirondev

Page 46: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Decomposition allows each small team to have ownership of a service

@kfirondev

Page 47: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Wix Org chart - “Guilds & Gangs”

@kfirondev

Micsroservices is the only way to support this HR methodology

Page 48: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

01 Resource Isolation by service level

Decompose to avoid competition of shared resources

02 Different release cycles

Decompose to meet your product’s life cycle strategy

03 Reuse and share logic

Decompose to share logic with dependencies

04 Develop & maintain by a single teamDecompose to meet your HR needs

@kfirondev

When to break the monolith

Page 49: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Microservices start from a monolith and should be created with caution

@kfirondev

Page 50: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

From monolith to microservices: Practices to start with

Page 51: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Make changes gradually

www.livbit.com@kfirondev

Page 52: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

@kfirondev

Don’t start with your most critical service

Page 53: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Confidence is built slowly

Page 54: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Use proper monitoring from day one

www.capacitysolutionsplatform.com

@kfirondev

Page 55: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Talk about failures and their causes

Page 56: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

The secret of getting ahead is getting started.

- Mark Twain

@kfirondev

Page 57: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Q&Alinkedin/in/blochkfir github.com/kfiron@[email protected]

Kfir Bloch

Page 58: The art of decomposing monoliths - Kfir Bloch - Codemotion Amsterdam 2016

Thank YouWix Engineering Blog http://engineering.wix.com/

We are hiring http://jobs.wix.com

Kfir Bloch @kfirondev

[email protected]