67
MONOLITH -> MICROSERVICES A GUIDED ADVENTURE @MIKEGEHARD, @PIVOTAL

The Journey from Monolith to Microservices: a Guided Adventure

  • Upload
    pivotal

  • View
    211

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Journey from Monolith to Microservices: a Guided Adventure

MONOLITH -> MICROSERVICES A GUIDED ADVENTURE

@MIKEGEHARD, @PIVOTAL

Page 2: The Journey from Monolith to Microservices: a Guided Adventure

ABOUT ME

▸ Working with clients to migrate legacy monoliths -> microservices

▸ Worked on the Spring Cloud Services team

▸ Trying not to be a Chief Principal Senior Consultant Scientist

Page 3: The Journey from Monolith to Microservices: a Guided Adventure

ABOUT YOU

▸ Have a monolith that needs migrating?

▸ Actively migrating a monolith?

▸ Building microservices net new?

▸ This talk has a little bit for all of you…

Page 4: The Journey from Monolith to Microservices: a Guided Adventure

AGENDA

▸ Where did these ideas come from?

▸ Which comes first?

▸ What is the path?

Page 5: The Journey from Monolith to Microservices: a Guided Adventure

BACKGROUND

Page 6: The Journey from Monolith to Microservices: a Guided Adventure

https://twitter.com/barinek

Page 7: The Journey from Monolith to Microservices: a Guided Adventure

HTTP://WWW.APPCONTINUUM.IO/

Page 8: The Journey from Monolith to Microservices: a Guided Adventure

https://twitter.com/simonbrown

Page 9: The Journey from Monolith to Microservices: a Guided Adventure

MODULAR MONOLITH

Page 10: The Journey from Monolith to Microservices: a Guided Adventure

NOTICE ANY SIMILARITIES?

Page 11: The Journey from Monolith to Microservices: a Guided Adventure

THIS SHOULD NOT BE REVOLUTIONARY

Page 12: The Journey from Monolith to Microservices: a Guided Adventure

WHICH COMES FIRST?

Page 13: The Journey from Monolith to Microservices: a Guided Adventure
Page 14: The Journey from Monolith to Microservices: a Guided Adventure

MONOLITH OR MICROSERVICES

Page 15: The Journey from Monolith to Microservices: a Guided Adventure

IT DEPENDS…

Page 16: The Journey from Monolith to Microservices: a Guided Adventure

HTTP://WWW.APPCONTINUUM.IO/

Page 17: The Journey from Monolith to Microservices: a Guided Adventure

MODULAR MONOLITH

Page 18: The Journey from Monolith to Microservices: a Guided Adventure

IF YOU CAN’T BUILD A WELL STRUCTURED MONOLITH, WHAT MAKES YOU THINK YOU CAN BUILD A WELL STRUCTURED SET OF MICROSERVICES?

UNKNOWN

TEXT

Page 19: The Journey from Monolith to Microservices: a Guided Adventure

WELL STRUCTURED MONOLITHWINNER?

Page 20: The Journey from Monolith to Microservices: a Guided Adventure

BOUNDARIES?

Page 21: The Journey from Monolith to Microservices: a Guided Adventure

BOUNDED CONTEXTS

Page 22: The Journey from Monolith to Microservices: a Guided Adventure

2003 2013

Page 23: The Journey from Monolith to Microservices: a Guided Adventure

SOUND FAMILAR?

Page 24: The Journey from Monolith to Microservices: a Guided Adventure

HOW DO I GET THERE?

Page 25: The Journey from Monolith to Microservices: a Guided Adventure
Page 26: The Journey from Monolith to Microservices: a Guided Adventure

GOALS

▸ Migrate a monolith that was in production, making money, to a more sustainable solution for the future.

▸ Architect for scalability of app in the future.

▸ Allow multiple teams to deliver business value quickly.

▸ Allow for addition of resources without overcrowding.

Page 27: The Journey from Monolith to Microservices: a Guided Adventure

CURRENT STATE

▸ API servers

▸ Multiple clients, including JavaScript front end

▸ Some dead code

▸ Lack of comprehensive, current API tests

Page 28: The Journey from Monolith to Microservices: a Guided Adventure
Page 29: The Journey from Monolith to Microservices: a Guided Adventure

WHERE DO WE START?

Page 30: The Journey from Monolith to Microservices: a Guided Adventure
Page 31: The Journey from Monolith to Microservices: a Guided Adventure
Page 32: The Journey from Monolith to Microservices: a Guided Adventure

GOAL: VALIDATE YOU DON'T BREAK ANY CLIENT FACING BEHAVIOR WHILE MIGRATING

STEP 1: API LEVEL TESTS

Page 33: The Journey from Monolith to Microservices: a Guided Adventure

CURRENT STATE

APICLIENT

CLIENT

CLIENT

CLIENT

Page 34: The Journey from Monolith to Microservices: a Guided Adventure

DESIRED END STATE

CLIENT

CLIENT

CLIENT

CLIENT

OLD API OLD API

OLD APIOLD API

Page 35: The Journey from Monolith to Microservices: a Guided Adventure

WHAT STAYED THE SAME?

Page 36: The Journey from Monolith to Microservices: a Guided Adventure

TESTS

APITEST

TEST

TEST

TEST

Page 37: The Journey from Monolith to Microservices: a Guided Adventure

HTTPS://GITHUB.COM/REALESTATE-COM-AU/PACT

Page 38: The Journey from Monolith to Microservices: a Guided Adventure

RESULT: YOU NOW KNOW WHEN YOU HAVE BROKEN USER FACING BEHAVIOR BEFORE YOU GO INTO PRODUCTION

Page 39: The Journey from Monolith to Microservices: a Guided Adventure

GOAL: BEGIN TO UNDERSTAND WHAT BOUNDED CONTEXTS EXIST

STEP 2: ARRANGE APPLICATION SO YOU CAN SEE YOUR DOMAIN

Page 40: The Journey from Monolith to Microservices: a Guided Adventure
Page 41: The Journey from Monolith to Microservices: a Guided Adventure
Page 42: The Journey from Monolith to Microservices: a Guided Adventure

STEP 2: ARRANGE APPLICATION SO YOU CAN SEE YOUR DOMAIN

▸ Minimizes the number of directories where changes happen.

▸ Less costly to experiment with/evolve bounded contexts.

▸ Delaying architecture decisions.

Page 43: The Journey from Monolith to Microservices: a Guided Adventure

GOAL: GIVE MORE SPACE IN THE CODEBASE AND SOLIDIFY DEPENDENCIES/BOUNDARIES.

STEP 3: BREAK OUT COMPONENTS

Page 44: The Journey from Monolith to Microservices: a Guided Adventure
Page 45: The Journey from Monolith to Microservices: a Guided Adventure
Page 46: The Journey from Monolith to Microservices: a Guided Adventure

WHAT ABOUT DATABASES?

▸ Application manages?

▸ Component manages?

▸ “It depends…”

Page 47: The Journey from Monolith to Microservices: a Guided Adventure

RULE: MIGRATIONS ONLY TOUCH ONE TABLE.

Page 48: The Journey from Monolith to Microservices: a Guided Adventure

WHY?

Page 49: The Journey from Monolith to Microservices: a Guided Adventure

STEP 3: BREAK OUT COMPONENTS

▸ More room in the codebase for multiple teams.

▸ Strict boundaries between framework code and domain code.

▸ Moving closer to microservices without the overhead of multiple processes.

▸ Stopping here gives you a lot of benefits without overhead of microservices.

Page 50: The Journey from Monolith to Microservices: a Guided Adventure

GOAL: IT DEPENDS…STEP 4: PROMOTE YOUR FIRST MICROSERVICE

Page 51: The Journey from Monolith to Microservices: a Guided Adventure

WHY EXTRACT A MICROSERVICE?

▸ Scaling a certain bounded context becomes an issue.

▸ You want to deploy one bounded context more frequently.

▸ Many, many other reasons that I won’t cover here.

Page 52: The Journey from Monolith to Microservices: a Guided Adventure
Page 53: The Journey from Monolith to Microservices: a Guided Adventure

WHY NOT EXTRACT A MICROSERVICE?

▸ Cost of managing the service outweighs the benefits.

▸ Dysfunctional communication patterns in the org

▸ Many, many other reasons that I won’t cover here.

Page 54: The Journey from Monolith to Microservices: a Guided Adventure

BILLING

EMAIL

Page 55: The Journey from Monolith to Microservices: a Guided Adventure

BILLING

EMAIL

Page 56: The Journey from Monolith to Microservices: a Guided Adventure

STEP 4: EXTRACT YOUR FIRST MICRO SERVICE

▸ Congratulations you now have a distributed system!!!

▸ And with that distributed system come new costs:

▸ Billing now needs to know how to contact the email service.

▸ Network communication between billing and email will fail at some point.

Page 57: The Journey from Monolith to Microservices: a Guided Adventure

GOAL: ABSTRACT LOCATION AND QUANTITY OF SERVICE INSTANCES

SERVICE DISCOVERY

Page 58: The Journey from Monolith to Microservices: a Guided Adventure

BILLING

EMAIL

SERVICE DISCOVERY

Page 59: The Journey from Monolith to Microservices: a Guided Adventure

SERVICE DISCOVERY

▸ Service calls are most loosely coupled to location and number of instances.

▸ Client side load balancing can reduce number of network calls.

▸ But there is an additional applications to run and monitor.

Page 60: The Journey from Monolith to Microservices: a Guided Adventure

GOAL: PROTECT AGAINST CASCADING FAILURES THAT CAUSE SYSTEM DOWNTIME

CIRCUIT BREAKER

Page 61: The Journey from Monolith to Microservices: a Guided Adventure
Page 62: The Journey from Monolith to Microservices: a Guided Adventure

BILLING

EMAIL

SERVICE DISCOVERY

CIRCUIT BREAKER

Page 63: The Journey from Monolith to Microservices: a Guided Adventure

CIRCUIT BREAKERS

▸ Increased resiliency of system when the network or a service fails...because they will.

▸ Increased visibility of health of system as a whole.

▸ But there is an additional applications to run and monitor.

Page 64: The Journey from Monolith to Microservices: a Guided Adventure

CONGRATULATIONS YOU ARE THE PROUD OWNER OF A SET OF MICROSERVICES!!

Page 65: The Journey from Monolith to Microservices: a Guided Adventure

NEXT STEPS

▸ Break out more microservices as necessary.

▸ Change up the communication interface...maybe use a message queue?

▸ Don't do anything and continue to make money.

▸ The choice is up to you!

Page 66: The Journey from Monolith to Microservices: a Guided Adventure

SOURCE CODE

▸ https://github.com/mikegehard/journeyFromMonolithToMicroservices (Java)

▸ https://github.com/mikegehard/user-management-evolution-kotlin (Kotlin)

Page 67: The Journey from Monolith to Microservices: a Guided Adventure

THANK YOU! QUESTIONS?

@MIKEGEHARD, @PIVOTAL