microservices - rainfocus · recipe: microservices (makes 5-10 microservices) ingredients: a...

130
Microservices A Tutorial Session JavaOne 2016

Upload: others

Post on 22-May-2020

31 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

MicroservicesA Tutorial Session

JavaOne 2016

Page 2: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

by Jason Swartz@swartzrock

Page 3: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

MICROSERVICES

Page 4: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

WHAT

WHYa.k.a “WHEN”

HOW

Page 5: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

What’s AMicroservice?

Page 6: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Your Application,Subdivided

Page 7: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Recipe: Microservices(makes 5-10 microservices)

Ingredients: ● A Monolithic API, Too Big To Handle

Instructions:1. Find the seams in your application - by operation, business area, or team.2. Split your API into multiple smaller API’s, each on its own server.3. Figure out how to deploy them w/o breaking everything.4. Figure out how they’ll talk to each other w/o breaking more things. 5. Figure out how complex data operations will work across multiple data stores.

Page 8: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 9: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 10: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 11: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Let’s Split-UpThat Service

Page 12: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 13: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 14: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 15: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Small & Maintainable2. Private data3. Generally Isolated

Microservice Properties

Page 16: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Small & Maintainable2. Private data3. Generally Isolated

Microservice Nice-To-Haves

Page 17: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Findable2. Scalable3. Resilient4. Monitorable

Microservice Nice-To-Haves

Page 18: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Microservices That Speak To Each Other Via Asynchronous Communication

Microservice Real Nice-To-Haves

Page 19: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 20: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Let’s See a Real

Transaction

Page 21: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Web Client: PUT issues/123 Assignee=10

Issues Service: Read from issues db

Issues Service: GET users/10

Issues Service: POST users/notify/10

Issues Service: Write to issues db

Issues Service: Return response with result

Web Client: Read response & status then handle it

Page 22: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Web Client: PUT issues/123 Assignee=10

Issues Service: Read from issues db

// block for synchronous transaction

// block for synchronous transaction

Issues Service: Write to issues db

Issues Service: Return response with result

Web Client: Read response & status then handle it

Page 23: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Blocking Isn’t Isolated, Scalable

Or Resilient

Page 24: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

But It Is Easy!

Page 25: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Easy!2. Gratifying.3. Testable.

Synchronous Messaging Pros

Page 26: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Prevents microservices from being isolated, scalable, and resilient.

2. Hope you like waiting.

Synchronous Messaging Cons

Page 27: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

MicroservicesShould Talk

Asynchronously

Page 28: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Non-Blocking IO (eg RxJava, Netty)2. Queues (eg SQS)3. Event Streams (eg Kafka, Kinesis)4. Actors (eg Akka)

Talking Asynchronously

Page 29: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

What About TheClients?

Page 30: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Synchronous REST with Async Clients2. Http 202 3. Websockets4. Http/2

Responding Asynchronously

Page 31: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

That’s What Microservices Are All

About

Page 32: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

WHAT

WHYa.k.a “WHEN”

HOW

Page 33: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

MonolithTo

Microservices

Page 34: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

WhyMight This Be A

Good Idea?

Page 35: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

(Assuming You’re Planning to Split Up your Monolith)

Page 36: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Finding code and refactoring it is pretty easy.2. No network lag3. No format conversion errors4. Deploy in one go

Monoliths - Not So Bad

Page 37: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

That’s AllThanks For Listening!

Page 38: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Hard to scale up just one feature2. Hard to deploy just one change3. Not suitable for more than a small team

Monoliths - Not So Scalable Either

Page 39: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Organizations Are Constrained To Produce

Designs That Match Their Communication Structure

Page 40: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 41: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Max Capacity:One Team

Page 42: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 43: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Max Capacity:Two Teams

Page 44: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Don’t Split MonolithsAcross Your

Communication Structures

Page 45: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

(we kind of covered this already)

Microservices Pros

Page 46: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Network Lag2. Multiple Data Formats3. Service Resolution4. Troubleshooting5. More Deployment Work6. More Monitoring

Microservices Challenges

Page 47: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

No Problem. Let’s Get Started On

HowYou’ll Build Em

Page 48: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

WHAT

WHYa.k.a “WHEN”

HOW

Page 49: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Microservices In Java

Page 50: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

How Will You Get Your App In

Production?

Page 51: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Self-Running Jar’s2. VM Images3. Docker Images

Deployment Formats

Page 52: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Use A CI To Build / Test / Merge in CI2. Use A CD To Deploy (Push-Button / Auto)3. VM Deployment (eg Spinnaker)4. Docker Deployment (eg ECS, K8s, Marathon)5. Cluster Management (eg K8s, Mesos, Swarm)

Deployment Strategies

Page 53: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Yes

Should I Deploy To The Cloud?

Page 54: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

YES OH YES

Should I Test It First?

Page 55: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Service Resolution (K8s, Consul)2. Scaling3. Visibility4. Authentication5. Monitoring

Microservice Management

Page 56: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Let’s TalkMicroservices

Development

Page 57: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

(why switch now?)

Choosing A Framework

Page 58: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Spring Boot2. Lagom3. Ratpack4. Dropwizard

Choosing A Framework

Page 59: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Good Ol’ SQL (eg MySQL, Postgresql)2. Document-type NoSQL3. Fast Key-Value Caches

Choosing A Data Store

Page 60: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. CRUD operations endpoints & tables2. CRUD endpoints and immutable tables3. Event-Sourced Data

Choosing A Data Scheme

Page 61: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Create-Read-Update-Delete

Page 62: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Let’s Talk AboutImmutable Tables

Page 63: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 64: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

GET /issuesGET /issues/{id}POST /issuesPUT /issues/{id}

Issue Endpoints

Page 65: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

How Do These EventsAffect The Database?

Page 66: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:13 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+

Page 67: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=10

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:16 | Config ELB | 10 | false |+------+-------------+------------+----------+-------+

Page 68: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Page 69: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Not Bad.

Page 70: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Do You Know How We Got Here?

Page 71: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Do You Know How We Got Here?

Page 72: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Do You Know How We Got Here?

Page 73: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Why is ‘assignee’ NULL?

Page 74: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Mutable Table Rows Lose History

Page 75: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Immutable Table Rows Keep Their History

Page 76: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Let’s Try To Lock Down

Our State

Page 77: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:13 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+

Page 78: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=10

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:13 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:16 | Config ELB | 10 | false |+------+-------------+------------+----------+-------+

Page 79: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:13 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:16 | Config ELB | 10 | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:19 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Page 80: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:13 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:16 | Config ELB | 10 | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:19 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Page 81: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. GET /issues/1

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:13 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:16 | Config ELB | 10 | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:19 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+

+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | NULL | true |+------+-------------+------------+----------+-------+

Page 82: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

How Do You Make An Append-Only

Table?

Page 83: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

One: Don’t Let Your DB User Make

Changes

Page 84: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Grant select, insert on issues to my-db-user;

Page 85: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Two: Pick The RightColumns

Page 86: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

create table issues ( id serial, created timestamp default now(), creator_id int, issue_id int default nextval(‘iseq’), title text, assignee int, done boolean default false)

Page 87: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Do We Still Need State?

Page 88: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Let’s Talk AboutEvent-Sourcing

Page 89: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:13 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:16 | Config ELB | 10 | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | 10 | true |+------+-------------+------------+----------+-------+

Page 90: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issues title=’Config ELB’2. PUT /issues/1 assignee=103. PUT /issues/1 done=true

+------+-------------+------------+----------+-------+| id | updated | title | assignee | done |+------+-------------+------------+----------+-------+| 1 | 09-18 18:13 | Config ELB | NULL | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:16 | Config ELB | 10 | false |+------+-------------+------------+----------+-------+| 1 | 09-18 18:24 | Config ELB | 10 | true |+------+-------------+------------+----------+-------+

Events

States

Page 91: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 92: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 93: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 94: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 95: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Now We’re Storing Events,

Not States

Page 96: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

create table issue_events ( id serial, created timestamp default now(), issue_id int default nextval(‘iseq’), originator text, payload text)

Page 97: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. POST /issue/1/event ‘Originator: 4a48239-8a..’ payload=’<Update val=”done=true”>’

+----+-------------+----------+------------+---------+| id | created | issue_id | originator | payload |+----+-------------+----------+------------+---------+| 14 | 09-18 18:50 | 1 | 4a482... | <...> |+----+-------------+----------+------------+---------+

Page 98: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Create Events AndSimulate The State

Page 99: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Create-Issue

Issue(“Config ELB”, null, false);

Real Events

Virtual States

Page 100: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Create-Issue2. Assign-Issue

Issue(“Config ELB”, 10, false);

Real Events

Virtual States

Page 101: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Create-Issue2. Assign-Issue3. Complete-Issue

Issue(“Config ELB”, 10, true);

Real Events

Virtual States

Page 102: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

So Why UseEvent-Sourcing?

Page 103: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. High Write Performance2. Potential for Command/Query Separation3. Auditable4. Replayable5. Undo-able6. Monitorable

Reasons For Event-Sourcing

Page 104: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

It’s Like Having Control Over The Versions Of

Your State Changes

Page 105: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

It’s Like Having Control Over The Versions Of

Your Data

Page 106: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

It’s Like GitFor Your Data

Page 107: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

1. Frankly, It’s Weird2. Requires Events. No Events, No Event-Sourcing.3. As Of Sept 2016, It’s Still Non-Standard

Reasons Against Event-Sourcing

Page 108: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

That About Sums Up Microservice Development

Page 109: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

That About Sums Up Microservice Development

Page 110: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Okay, Actually That’s The Entire Session

Unless There’s More Time

Page 111: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

WHAT

WHYa.k.a “WHEN”

HOW

Page 112: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

by Jason Swartz@swartzrock

Page 113: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

MicroservicesA Tutorial Session

JavaOne 2016

Page 114: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Web Applications for the REST of Us: An Introduction to Ember.js, Akka, and Spray (Craig Tataryn & Sean Kowaski)

A Practical RxJava Example with Ratpack (Laurent Doguin)

One Microservice Is No Microservice: They Come In Systems (Markus Eisele)

Make Sure To See...

Page 115: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Thank You For Attending

Page 116: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Fin

Page 117: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Just Kidding, There’s Another Section

Page 118: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Let’s Talk Asynchronous

Architectures in AWS

Page 119: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Do You Want To Use Caches To Prevent

Unnecessary Blocking Calls?

Page 120: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 121: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Do You Want To Insert Rows And Publish

Events In One Stroke?

Page 122: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 123: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 124: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Do You Want To Mass-Publish One Event

To All Microservices?

Page 125: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 126: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application
Page 127: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Note About Your Solution:I’m Not Saying It’s AWS

Page 128: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

But It’s AWS

Page 129: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

Okay, We Are Really Done This Time

Page 130: Microservices - RainFocus · Recipe: Microservices (makes 5-10 microservices) Ingredients: A Monolithic API, Too Big To Handle Instructions: 1. Find the seams in your application

THIS SPACELEFT BLANK