microservices communication and integration: what are my … · 2019-09-11 · microservices...

35
Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus – February 2016

Upload: others

Post on 20-May-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Microservices communication and integration: what are my options?

Kate Stanley

@KateStanley91

Jfokus – February 2016

Page 2: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Introduction

Software engineer

WebSphere Liberty

Microservices

@KateStanley91

Page 3: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Contents

What are microservices?

Why is communication important?

Microservice communication options

Producing and consuming APIs

Conclusion

Page 4: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

What are microservices?

Page 5: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

…compose a complex application using:“small”

independent (autonomous)

replaceable

processes

…that communicate via:language-agnostic APIs

Microservices are used to…

Microservice

MicroserviceMicroservice

Microservice

Microservices application

Subscribe

REST

(JSON/HTTP)

Microservice

Microservice

broker

API

MicroservicePublish

API

REST

(JSON/HTTP)

Publish

Service

Registry

API

Microservice

Page 6: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Why is communication important?

Page 7: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

How my team communicates

Different locations

Different timezones

Different languages…?!

“The United States and Great Britain are two countries separated by a common language.”

Page 8: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

How my team communicates

Data type:Text, speech, body language

Infrastructure:Email, Slack, Skype

Characteristics:Delayed (Email) / Immediate (Skype)

Hello!

Howdy!

Page 9: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Data type:JSON / XML / binary

Infrastructure:Service registry

Service proxy

Characteristics:Asynchronous

Synchronous

Microservices communication

Microservice Microservice

Microservice

?

Page 10: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Communication infrastructure options

Page 11: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Service Registry

Store of available microservices

Provides:Registration, Healthcheck, Service Discovery, De-registration

Consistency vs Availability

Examples:Eureka, Consul, Amalgam8

Page 12: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Routing via service proxy

AdvantagesSimple requests

Simple tests Microservice

Microservice

Service

Registry

Service

Proxy

Registry requests

Proxy requests

Page 13: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Routing via service proxy

DisadvantageMore network hops

Microservice

Microservice

Service

Registry

Service

Proxy

1

23

4

Registry requests

API requests

Page 14: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Client-side routing

Less network hops

Microservice MicroserviceService

Registry

1

2

Registry requests

API requests

Page 15: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Client-side routing

Client libraryLanguage specific

Easy debugging

SidecarLanguage agnostic

Harder to debug failures

Microservice

Microservice

Microservice

Service

Registry

Client library

app

sidecar Registry requestsAPI requests

Page 16: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

API Gateway

Provides coarse grained APIs

Useful for:API metering

JWT injection

Microservice

Microservice

Microservices application

REST

(JSON/HTTP)

Microservice

API

MicroservicePublish

API

REST

(JSON/HTTP)

Service

Registry

API

API Gateway

Page 17: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Communication characteristics

Page 18: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Synchronous vs asynchronous protocol

Synchronous e.g. REST, HTTPRequires a response

Utilise asynchronous programming model

Asynchronous e.g. messagingNo response required

Page 19: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Example – Game On

Page 20: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Example – Game On!

Interactive mapOutside of core microservices

Displays room location and name

Page 21: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Example – Game On

Page 22: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

ExternalDatastore Interactive Map

Map Service

Network boundary

Logical boundary

Rest/HTTP

API

Authenticated User

Broker

Publish

Subscribe

(1)

(2)

(3)

(4)

Page 23: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Messaging in Game On!

Apache Kafka locally

MessageHub in the cloud

Page 24: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Microservice design

Design influenced by communication

Consider latencyMicroservice

MicroserviceMicroservice

Microservice

Microservices application

Subscribe

REST

(JSON/HTTP)

Microservice

Microservice

broker

API

MicroservicePublish

API

REST

(JSON/HTTP)

Publish

Service

Registry

API

Microservice

Page 25: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

ELK mongo

room

Player

Proxy

JSON/HTTP (REST)

Concierge

• Player managed ”all interactions with the player”

• Concierge: tell player service which room is next

(/go N)

• Room (had to have one!)

First pass

Page 26: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

kafkaELK couchdb

room

Player

Proxy

Mediator

Now..

Concierge

Page 27: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Producing and consuming APIs

Page 28: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

APIs change!

Breaking changesAlter methods and data

Non-breaking changes (theoretically!)Add data or methods

Page 29: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Being a good consumer

Accept the unknown

Only validate against the required

Fault tolerance important – another talk!

Page 30: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Being a good producer

Golden rule: don’t break your consumers

If you need to break something - use versioning

Accept unknown attributes

Only return attributes relevant to the request

Page 31: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Robustness principle

“Be conservative in what you send,

be liberal in what you accept”

https://en.wikipedia.org/wiki/Robustness_principle

Page 32: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Documenting APIs

Consumer driven contract tests

Swagger

Page 33: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Conclusion

Page 34: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Conclusion

Choose service discovery and invocation method

Use both asynchronous and synchronous protocols

Design influenced by communication

Robustness principle

Page 35: Microservices communication and integration: what are my … · 2019-09-11 · Microservices communication and integration: what are my options? Kate Stanley @KateStanley91 Jfokus

Thank you!

Play the game – http://gameontext.org

Build rooms – http://github.com/gameontext

Learn more:

http://wasdev.net

Microservices Best Practices for Java http://www.redbooks.ibm.com

Kate Stanley | [email protected] | @KateStanley91