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

The art of decomposing monoliths

Embed Size (px)

Citation preview

Page 1: The art of decomposing monoliths

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
Page 3: The art of decomposing monoliths
Page 4: The art of decomposing monoliths

Wix in Numbers Over

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 5: The art of decomposing monoliths

Wix R&D ●  Scala

●  React

●  Angular

~350 engineers in 3 locations (Tel Aviv, Dnipropetrovsk & Vilnius)

●  TDD

●  Continuous delivery

@kfirondev

Page 6: The art of decomposing monoliths

Wix and Microservices In 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

~150 different services

@kfirondev

Page 7: The art of decomposing monoliths

@kfirondev

Page 8: The art of decomposing monoliths

Microservices is the new black

@kfirondev

Page 9: The art of decomposing monoliths

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

Microservices characteristics

Protocol

Circuit Breaker

SOA

Service Discovery

Cascading Failure

Replaceable Units

Service Graph

Scalable Units

Documentation

www.maplecityrubber.com @kfirondev

Page 11: The art of decomposing monoliths

But I will talk about: When (and when NOT) to decompose your monolith

@kfirondev

Page 12: The art of decomposing monoliths

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

@kfirondev

Sometimes less is more

Page 13: The art of decomposing monoliths

Microservices have trade-offs

@kfirondev

Page 14: The art of decomposing monoliths

Each I/O hop is a failure point

Partial deployment

Strong interfaces between services are harder to refactor

Ops complexity End-to-end testing is challenging

@kfirondev

Page 15: The art of decomposing monoliths

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

Mitigations ●  Partial deployment

○  Feature toggle mechanism

@kfirondev

Page 17: The art of decomposing monoliths

Mitigations ●  Ops complexity

○  Automation ○  Developers own the Ops

@kfirondev

Page 18: The art of decomposing monoliths

Mitigations ●  Strong interface – hard to refactor

○  Backward / forward compatibility ○  Strong build system - dependency

○  Proper contact tests

@kfirondev

Page 19: The art of decomposing monoliths

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

@kfirondev

Page 20: The art of decomposing monoliths

Once we accept our limits, we go beyond them. - Albert Einstein

@kfirondev

Page 21: The art of decomposing monoliths

To microserviceor not to microservice?

@kfirondev

Page 22: The art of decomposing monoliths

Decompose to gain resource isolation for high availability

01

Page 23: The art of decomposing monoliths

File Upload

Client Web File

Storage

Items (CRUD) Items DB Items 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

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

Decompose to avoid competition on shared resources

@kfirondev

Page 26: The art of decomposing monoliths

File Upload

Client Web File

Storage

Items (CRUD) Items DB Items Catalog

Service

@kfirondev

Page 27: The art of decomposing monoliths

File Upload

Client Web File

Storage

Items (CRUD) Items DB

Items Service

Files Service

@kfirondev

Page 28: The art of decomposing monoliths

Decompose by different life cycles

02

Page 29: The art of decomposing monoliths

4 PM Deploy – Items catalog feature

BI Storage

Items (CRUD) Items DB Items Catalog

Service Coupons

@kfirondev

5 PM Deploy – Coupon feature 6 PM Deploy – Coupon feature 9 PM Deploy – Coupon feature 12 AM Rollback – Due to bug in items catalog

THE COMPANY LOSES MONEY

Page 30: The art of decomposing monoliths

Items (CRUD) Items DB Items Catalog

Service Coupons

@kfirondev

B1 Storage

Page 31: The art of decomposing monoliths

B1 Storage

Items (CRUD) Items DB

Coupons Service

Items Catalog Service

@kfirondev

Page 32: The art of decomposing monoliths

03 Decompose to reuse and share logic

Page 33: The art of decomposing monoliths

Google

Items DB Items Catalog

Service Geo

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

Google

Items DB Items Catalog

Service

Geo (3rd party)

Geo DB

Geo

User Management Service

User DB

Geo Service Fetch Geo Fetch Geo

@kfirondev

Page 35: The art of decomposing monoliths

Google

Items DB Items Catalog

Service Geo

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

Each service must have its own DB

@kfirondev

Page 37: The art of decomposing monoliths

DB

Service A

An example when not to decompose

Extract Cookie Info

DB

Service B

Extract Cookie Info

@kfirondev

Page 38: The art of decomposing monoliths

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

@kfirondev

Page 39: The art of decomposing monoliths

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

@kfirondev

Page 40: The art of decomposing monoliths

04 Decompose to have single team responsibility

Page 41: The art of decomposing monoliths

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

@kfirondev

Decompose to support organization scalability

Page 43: The art of decomposing monoliths

Large teams cannot efficiently handle a large code base

@kfirondev

Small teams embrace responsibility and accountability

Page 44: The art of decomposing monoliths

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

@kfirondev

Page 45: The art of decomposing monoliths

Decomposition allows each small team to have ownership of a service

@kfirondev

Page 46: The art of decomposing monoliths

Wix Org chart - “Guilds & Gangs”

@kfirondev

Microservices is the only way to support this HR methodology

Page 47: The art of decomposing monoliths

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 team Decompose to meet your HR needs

@kfirondev

When to break the monolith

Page 48: The art of decomposing monoliths

Microservices start from a monolith and should be created with caution

@kfirondev

Page 49: The art of decomposing monoliths

From monolith to microservices: Practices to start with

Page 50: The art of decomposing monoliths

Make changes gradually

www.livbit.com @kfirondev

Page 51: The art of decomposing monoliths

@kfirondev

Don’t start with your most critical service

Page 52: The art of decomposing monoliths

Confidence is built slowly

Page 53: The art of decomposing monoliths

Use proper monitoring from day one

www.capacitysolutionsplatform.com

@kfirondev

Page 54: The art of decomposing monoliths

Talk about failures and their causes

Page 55: The art of decomposing monoliths

The secret of getting ahead is getting started. - Mark Twain

@kfirondev

Page 56: The art of decomposing monoliths

Q&A linkedin/in/blochkfir github.com/kfiron @kfirondev [email protected]

Kfir Bloch

Page 57: The art of decomposing monoliths

Thank You Wix Engineering Blog http://engineering.wix.com/

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

Kfir Bloch @kfirondev

email [email protected]