43
Microservices In a Legacy Environment Principles & Examples

Bootiful Microservices in a Legacy Environment: Lessons Learned

  • Upload
    pivotal

  • View
    294

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Bootiful Microservices in a Legacy Environment: Lessons Learned

Microservices In a Legacy Environment

Principles & Examples

Page 2: Bootiful Microservices in a Legacy Environment: Lessons Learned

David Julia

@DavidJulia [email protected] Associate Director

Page 3: Bootiful Microservices in a Legacy Environment: Lessons Learned

In a Microservices Architecture

Services are cheap and fast to deploy and change independently.

Page 4: Bootiful Microservices in a Legacy Environment: Lessons Learned

Spring BootSimple and cheap to spin up a new microservice!

Autoconfiguration for standard boilerplate config

Page 5: Bootiful Microservices in a Legacy Environment: Lessons Learned

Legacy Environment: An environment wherein many systems that are hard to change are in dire need of replacement or augmentation to meet business demands.

Page 6: Bootiful Microservices in a Legacy Environment: Lessons Learned

This talk is for Developers. I want to show you how to get to microservices when you’re starting with a Big Ball of Mud.

Page 7: Bootiful Microservices in a Legacy Environment: Lessons Learned

The Importance of DDD in Legacy Environments

Don’t couple your domain model to your legacy systems’ models

Represent the latest business processes in code

Page 8: Bootiful Microservices in a Legacy Environment: Lessons Learned

Appcontinuum.io (thanks Mike Barinek)!

Evolving Components & Services

Page 9: Bootiful Microservices in a Legacy Environment: Lessons Learned

How do I break them out safely?

Page 10: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 11: Bootiful Microservices in a Legacy Environment: Lessons Learned

Succession /səәkˈseSHəәn/ Noun

The art of taking a single conceptual change, breaking it into safe steps, and then finding an order for those steps that optimizes safety, feedback, and efficiency

Page 12: Bootiful Microservices in a Legacy Environment: Lessons Learned

Succession Patterns let’s talk about a few

Page 13: Bootiful Microservices in a Legacy Environment: Lessons Learned

Strangler Application Pattern

Gradually create a new system around the edges of the old, letting it grow slowly over several years until the old system is

strangled

Page 14: Bootiful Microservices in a Legacy Environment: Lessons Learned

Characterization tests - a vice

Page 15: Bootiful Microservices in a Legacy Environment: Lessons Learned

An example:

Large fast food restaurant chain writing a mobile app

Replace rewards points vendor with their own system

Page 16: Bootiful Microservices in a Legacy Environment: Lessons Learned

Cut cost

Show reward points on iOS app

Set ourselves up to add new features

Motivation

Page 17: Bootiful Microservices in a Legacy Environment: Lessons Learned

First, let’s tackle viewing current rewards point

balance on iOS

Page 18: Bootiful Microservices in a Legacy Environment: Lessons Learned

Let’s look at our systems!

Page 19: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 20: Bootiful Microservices in a Legacy Environment: Lessons Learned

Let’s look at part of our Ball of Mud POS!

Page 21: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 22: Bootiful Microservices in a Legacy Environment: Lessons Learned

What’s the plan?

● Identify behavior we need.

● “Sprout” a new class to hold the behavior we want

● Start moving behavior into that class

● Extract a component (JAR) and break dependencies

Could stop here and use the library in our mobile API gateway. Or continue on and extract a service.

Page 23: Bootiful Microservices in a Legacy Environment: Lessons Learned

Sprout Method & Sprout Class

Sprouting = extracting new behavior

to a new method or class.

Can then add tests/new behavior

Page 24: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 25: Bootiful Microservices in a Legacy Environment: Lessons Learned

And now sprout component (jar)

Page 26: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 27: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 28: Bootiful Microservices in a Legacy Environment: Lessons Learned

But is it safe? i.e. “Does it match the website’s balance?”

Page 29: Bootiful Microservices in a Legacy Environment: Lessons Learned

Remember that web interface? it’s a test oracle!…Record any Δ’s

as bugs, and fix them.

Page 30: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 31: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 32: Bootiful Microservices in a Legacy Environment: Lessons Learned

We’re liking what we’re seeing… No Δ’s

Page 33: Bootiful Microservices in a Legacy Environment: Lessons Learned

“That diff thing won’t work for me!”

“I have mutating operations (edits/deletes)!”Same basic strategy, one modification:Noop in your new service implementationLog what you “would have done”

This is just one example of succession. Creativity is often required :)

*level of caution can be adjusted to your risk profile

Page 34: Bootiful Microservices in a Legacy Environment: Lessons Learned

Now Let’s extract a service!

Page 35: Bootiful Microservices in a Legacy Environment: Lessons Learned

But first… A note on premature extraction

Extracting a service too early can be costly

It’s easier to refactor the system with an in-process component

Easier to change your abstractions (interface changes)

Only have to change things in one place

Page 36: Bootiful Microservices in a Legacy Environment: Lessons Learned

Extract a service!

Let’s say we want a separate service**

● Extract a service, implement a remote façade at the seam we created

● Point iOS application API Gateway at the service

● Celebrate!

**for more info on when to extract a microservice vs stay with shared libraries, see Mike Gehard’s talk

Page 37: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 38: Bootiful Microservices in a Legacy Environment: Lessons Learned

Finally, add a mobile API Gateway

and iOS app!

Page 39: Bootiful Microservices in a Legacy Environment: Lessons Learned
Page 40: Bootiful Microservices in a Legacy Environment: Lessons Learned

What did we just see

Started with a ball of mud

Identified/Extracted behavior into new classes

Packaged classes as JAR

Created a new service (strangler application)

Did all of this safely and with high confidence

Page 41: Bootiful Microservices in a Legacy Environment: Lessons Learned

Next Steps

• Continue to move rewards-specific behavior to our service

• Could refactor the web GUI to use our new service

Page 42: Bootiful Microservices in a Legacy Environment: Lessons Learned

Thanks! ...Questions?

Page 43: Bootiful Microservices in a Legacy Environment: Lessons Learned

Appendix/Links

Mike Barinek’s appcontinuum.io

Simon Brown on Modular Monoliths http://www.codingthearchitecture.com/presentations/sa2015-modular-monoliths

Mike Gehard on Microservices https://vimeo.com/album/4045988/video/172421431

Working Effectively With Legacy Code by Michael Feathers