84
How Small Can Java Microservices Be? Eberhard Wolff Fellow, innoQ @ewolff

How Small Can Java Microservices Be?

Embed Size (px)

Citation preview

Page 1: How Small Can Java Microservices Be?

How Small Can Java Microservices Be?

Eberhard WolffFellow, innoQ

@ewolff

Page 2: How Small Can Java Microservices Be?

http://continuous-delivery-buch.de/

Page 3: How Small Can Java Microservices Be?

http://microservices-buch.de/ http://microservices-book.com/

Page 4: How Small Can Java Microservices Be?

http://microservices-book.com/primer.html

FREE!!!!

Page 5: How Small Can Java Microservices Be?

Microservice Definition

Page 6: How Small Can Java Microservices Be?

Microservices: Definition

> No consistent definition

> Microservices are modules

> Independent deployment units

> E.g. processes, Docker container

> Microservice owned by one team

Page 7: How Small Can Java Microservices Be?

Microservices: Definition

Server /Container

Server / Container

MicroService

MicroService

Page 8: How Small Can Java Microservices Be?

Components Collaborate

MicroService

MicroService

Link

Data Replication

RESTMessaging

Page 9: How Small Can Java Microservices Be?

Online Shop

Order

Catalog

Search

Billing

Customer

HTML /HTTP

Page 10: How Small Can Java Microservices Be?

Online Shop

Elasticsearch

Spring BatchOracle

Spring MVCMongoDB

Order

Catalog

Search

Billing

Page 11: How Small Can Java Microservices Be?

Microservices Stack

Page 12: How Small Can Java Microservices Be?

Docker

> Linux (soon Windows)

> Shared kernel

> Filesystem just stores diffs

> Extremely light weight

> Can run in cluster (e.g. Kubernetes, Mesosphere etc)

Page 13: How Small Can Java Microservices Be?

Spring Boot

> One build file

> One Java class

> = REST service + embedded Tomcat

> Deploy: One Java Fat JARs

> Alternatives: Dropwizard, Wildfly Swarm…

> https://github.com/ewolff/spring-boot-demos

Page 14: How Small Can Java Microservices Be?

Microservice = Fat JAR +Java EE programming model

possible!

Page 15: How Small Can Java Microservices Be?

Ideal size of a Microservice

Team size

Modularization

Infrastructure

Distributed Communication

No absolute value!

Replaceability

Microservice Size

Page 16: How Small Can Java Microservices Be?

Nanoservices

Page 17: How Small Can Java Microservices Be?

Nanoservices?

Page 18: How Small Can Java Microservices Be?

Nanoservices?

#SRSLY?

Page 19: How Small Can Java Microservices Be?

#SRSLY?

YES!

Page 20: How Small Can Java Microservices Be?

Nanoservices!=Microservices

Page 21: How Small Can Java Microservices Be?

Nanoservices<Microservices

Page 22: How Small Can Java Microservices Be?

Ideal size of a Microservice

Team size

Modularization

Infrastructure

Distributed Communication

No absolute value!

Replaceability

Microservice Size

Page 23: How Small Can Java Microservices Be?

Microservices=Independent

Deployment Units

Page 24: How Small Can Java Microservices Be?

Nanoservices=Independent

Deployment Units

Page 25: How Small Can Java Microservices Be?

Nanoservices use more light weight

technologies

Page 26: How Small Can Java Microservices Be?

Serverless

Page 27: How Small Can Java Microservices Be?

Serverless

> Deploy a function

> Pay per call

> Example: Amazon Lambda

> Similar: Google Cloud Functions

> Azure Functions

> IBM OpenWhisk (Open Source)

Page 28: How Small Can Java Microservices Be?

Serverless vs. PaaS

Page 29: How Small Can Java Microservices Be?

Amazon Lambda

> Service in the Amazon Cloud

> Allows you to install individual functions

> Java, JavaScript, Python

Page 30: How Small Can Java Microservices Be?

Amazon Lambdavs. PaaS

> Commercial model:Pay-per-call / RAM / processing time

> Fine grained (e.g. database trigger, HTTP GET)

> First million requests /400.000 DB seconds FREE!

> Can edit Python / JavaScript functions in the browser

Page 31: How Small Can Java Microservices Be?

LambdaFunction

Command Line

S3 Event

KinesisStream

DynamoDB

SNS: SimpleNotification Service

SES: SimpleEMail Service Cognito

CloudWatch

CloudFormation

API Gateway(e.g. REST)

ScheduledEvents

Page 32: How Small Can Java Microservices Be?

Amazon Lambda adds e.g. trigger to DynamoDB.

Page 33: How Small Can Java Microservices Be?

Amazon Lambda+ API Gateway

= REST services.

Page 34: How Small Can Java Microservices Be?

public class Main {

public String myHandler(int myCount,

Context context) {

LambdaLogger logger = context.getLogger();

logger.log("received : " + myCount);

return "Hi"+myCount;

}}

Page 35: How Small Can Java Microservices Be?

Deploy

Page 36: How Small Can Java Microservices Be?

Deploy

Page 37: How Small Can Java Microservices Be?

Deploy

Page 38: How Small Can Java Microservices Be?

Deploy

Page 39: How Small Can Java Microservices Be?

Deploy

Page 40: How Small Can Java Microservices Be?

Deploy

Page 41: How Small Can Java Microservices Be?

Deploy

Page 42: How Small Can Java Microservices Be?

Invoke

Page 43: How Small Can Java Microservices Be?

Invoke

Page 44: How Small Can Java Microservices Be?

Invoke

Page 45: How Small Can Java Microservices Be?

Invoke

Page 46: How Small Can Java Microservices Be?

Invoke

Page 47: How Small Can Java Microservices Be?

Invoke

Page 48: How Small Can Java Microservices Be?
Page 49: How Small Can Java Microservices Be?
Page 50: How Small Can Java Microservices Be?

Amazon Lambda

> Can add any other Amazon Service to complete the system

> i.e. Beanstalk PaaS, EC2 IaaS …

> Or databased (DynamoDB, RDS...)

Page 51: How Small Can Java Microservices Be?

Send out slidesvia email!

Page 52: How Small Can Java Microservices Be?

LambdaFunction

Simple EmailService

SMTP

Simple EmailService

Event

callsAudience

Cost: SES 0,10$ per 1000 EMailsLambda free

Page 53: How Small Can Java Microservices Be?

> Developed in Python

> In the browser

> ”Save & test”

> Includes monitoring & alarm

> Setting up SES was the hardest part…

Page 54: How Small Can Java Microservices Be?
Page 55: How Small Can Java Microservices Be?

OSGi

Page 56: How Small Can Java Microservices Be?

OSGi: Bundles

> Partition system into – "bundles”

> Bundles can be installed, started, stopped, uninstalled and updated

> ...at runtime

Page 57: How Small Can Java Microservices Be?

OSGi: Code Sharing

> Bundles can export and import packages

> Updating code requires other bundles to start fresh

Page 58: How Small Can Java Microservices Be?

OSGi: Services> Bundles can publish services… dynamically!

> Service = Java Object

> Service Registry allows other bundles to consume services

> Services come and go at runtime

> Quite easy with OSGi Blueprints or OSGiDeclarative Services

Page 59: How Small Can Java Microservices Be?

CallingBundle

Bundle (interfacecode)

Bundle(implementation

and service)

Service

Package(interface

code)

Package(interface

code)

Update to servicein running application

Page 60: How Small Can Java Microservices Be?

(Almost)Independent

Deployment Units

Page 61: How Small Can Java Microservices Be?

Java EE

Page 62: How Small Can Java Microservices Be?

Java EE

> JARs e.g. for EJBs

> WARs e.g. for web application

> EARs for JARs and WARs

> Completely separated code

> …unlike OSGi

Page 63: How Small Can Java Microservices Be?

Java EE

> Relevant: Deployment model

> i.e. application server

> Not programming model

Page 64: How Small Can Java Microservices Be?

Java EE Nanoservices?

> Local calls not possible

> No shared code e.g. for interfaces

Page 65: How Small Can Java Microservices Be?

Tomcat Java EEServer

order.war

customer.war

catalog.warCustomer

Page 66: How Small Can Java Microservices Be?

(Almost)Independent

Deployment Units

Page 67: How Small Can Java Microservices Be?

Comparison

Page 68: How Small Can Java Microservices Be?

Independent Deployment

> THE feature of Micro-/Nanoservices

> Simplifies to put new features in production

> Docker Fat JAR: ++

> Amazon Lambda: ++

> OSGi: + Restart the whole JVM?

> Java EE: + Restart the whole JVM?

Page 69: How Small Can Java Microservices Be?

Benefits of Nanoservices

Page 70: How Small Can Java Microservices Be?

Effort per Service

> How hard is it to create another service?

> All: Create another project/JAR/WAR

> Amazon Lambda: ++

> OSGi: ++

> Java EE: ++

> Docker Fat JAR : - (Docker container etc)

Page 71: How Small Can Java Microservices Be?

Cost per Service

> Hardware, software cost

> Amazon Lambda: ++

> OSGi: ++

> Java EE: ++

> Docker Fat JAR: -- (need Docker container etc, separat JVM Heap)

Page 72: How Small Can Java Microservices Be?

Local Communcation

> Call without network stack

> Docker Fat JAR : --

> Amazon Lambda: --

> OSGi: ++

> Java EE: --

Page 73: How Small Can Java Microservices Be?

Challenges of Nanoservices

Page 74: How Small Can Java Microservices Be?

Independent Scaling

> Start more instances of a single service

> Docker Fat JAR: ++

> Amazon Lambda: ++

> OSGi: ?

> Java EE: --

Page 75: How Small Can Java Microservices Be?

Isolation

> CPU / Memory consumption/crash influences other services

> Docker Fat JAR: ++

> Amazon Lambda: ++

> OSGi: --

> Java EE: --

Page 76: How Small Can Java Microservices Be?

Resilience & Isolation

> Resilience: System can handle crash of other services

> Needs isolation

> Problem for OSGi/Java EE

Page 77: How Small Can Java Microservices Be?

Technology Freedom

> Using different technologies

> Docker Fat JAR: ++ (whatever)

> Amazon Lambda: +(Java, JavaScript, Python)

> OSGi: -- (Java)

> Java EE: -- (Java)

Page 78: How Small Can Java Microservices Be?

Conclusion

Page 79: How Small Can Java Microservices Be?

Nanoservices!=Microservices

Page 80: How Small Can Java Microservices Be?

Nanoservices<Microservices

Page 81: How Small Can Java Microservices Be?

Conclusion> Nanoservice technologies compromise

> …to allow smaller services

> …to allow local communication

> OSGi and Java EE deployment model don’t fully support independent deployment

> …might therefore not be “true” Nanoservices

Page 82: How Small Can Java Microservices Be?

Conclusion

> OSGi and Java EE weak concerning

> Independent scaling

> Isolation

> Technology freedom

> Amazon Lambda a lot stronger

Page 83: How Small Can Java Microservices Be?

Might also consider…

> Vert.x:polyglot, distributed, module concept

> Erlang:support update to running system and processes in other languages

Page 84: How Small Can Java Microservices Be?

Thank You!

@ewolff

http://microservices-buch.de/

http://microservices-book.com/primer.html

http://aws.amazon.com/lambda/getting-started/

http://www.heise.de/developer/artikel/Nanoservices-kleiner-als-Microservices-3038541.html