Top Banner
Microservices & Nanoservices with Java Eberhard Wolff Fellow, innoQ @ewolff
67

Nanoservices and Microservices with Java

Apr 16, 2017

Download

Technology

Eberhard Wolff
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Nanoservices and Microservices with Java

Microservices & Nanoservices with Java

Eberhard WolffFellow, innoQ

@ewolff

Page 2: Nanoservices and Microservices with Java

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

Page 3: Nanoservices and Microservices with Java

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

FREE!!!!

Page 4: Nanoservices and Microservices with Java

Microservice Definition

Page 5: Nanoservices and Microservices with Java

Server Server

Microservices: Definition

> Independent deployment units

> Separate VM / process

> Any technology

> Any infrastructure

MicroService

MicroService

Page 6: Nanoservices and Microservices with Java

Microservices=Independent

Deployment Units

Page 7: Nanoservices and Microservices with Java

Components Collaborate

MicroService

MicroService

Link

Data Replication

RESTMessaging

Page 8: Nanoservices and Microservices with Java

Online Shop

Order

Catalog

Search

Billing

Customer

HTML /HTTP

Page 9: Nanoservices and Microservices with Java

Online Shop

Elasticsearch

Spring BatchOracle

Spring MVCMongoDB

Order

Catalog

Search

Billing

Page 10: Nanoservices and Microservices with Java

Microservices Stack

Page 11: Nanoservices and Microservices with Java

Docker

> Linux (soon Windows)

> Shared kernel

> Filesystem just stores diffs

> Extremely light weight

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

Page 12: Nanoservices and Microservices with Java

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 13: Nanoservices and Microservices with Java

Microservice = Fat JAR +Java EE programming model

possible!

Page 14: Nanoservices and Microservices with Java

Ideal size of a Microservice

Team size

Modularization

Infrastructure

Distributed Communication

No absolute value!

Replaceability

Microservice Size

Page 15: Nanoservices and Microservices with Java

Nanoservices

Page 16: Nanoservices and Microservices with Java

Nanoservices?

Page 17: Nanoservices and Microservices with Java

Nanoservices?

#SRSLY?

Page 18: Nanoservices and Microservices with Java

#SRSLY?

YES!

Page 19: Nanoservices and Microservices with Java

Nanoservices!=Microservices

Page 20: Nanoservices and Microservices with Java

Nanoservices<Microservices

Page 21: Nanoservices and Microservices with Java

Ideal size of a Microservice

Team size

Modularization

Infrastructure

Distributed Communication

No absolute value!

Replaceability

Microservice Size

Page 22: Nanoservices and Microservices with Java

Microservices=Independent

Deployment Units

Page 23: Nanoservices and Microservices with Java

Nanoservices=Independent

Deployment Units

Page 24: Nanoservices and Microservices with Java

Nanoservices use more light weight

technologies

Page 25: Nanoservices and Microservices with Java

Amazon Lambda

Page 26: Nanoservices and Microservices with Java

Amazon Lambda

> Service in the Amazon Cloud

> Allows you to install individual functions

> Java, JavaScript, Python

Page 27: Nanoservices and Microservices with Java

LambdaFunction

Command Line

S3 Event

KinesisStream

DynamoDB

SNS: SimpleNotification Service

SES: SimpleEMail Service Cognito

CloudWatch

CloudFormation

API Gateway(e.g. REST)

ScheduledEvents

Page 28: Nanoservices and Microservices with Java

Amazon Lambda adds e.g. trigger to DynamoDB.

Page 29: Nanoservices and Microservices with Java

Amazon Lambda+ API Gateway

= REST services.

Page 30: Nanoservices and Microservices with Java

public class Main {

public String myHandler(int myCount,

Context context) {

LambdaLogger logger = context.getLogger();

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

return "Hi"+myCount;

}}

Page 31: Nanoservices and Microservices with Java

Deploy

Page 32: Nanoservices and Microservices with Java

Deploy

Page 33: Nanoservices and Microservices with Java

Invoke

Page 34: Nanoservices and Microservices with Java
Page 35: Nanoservices and Microservices with Java
Page 36: Nanoservices and Microservices with Java

Amazon Lambda vs. PaaS

> Commercial model: Pay-per-call

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

> First million requests FREE!

> Can edit Python / JavaScript function in the browser

Page 37: Nanoservices and Microservices with Java

Amazon Lambda

> Can add any other Amazon Service to complete the system

> i.e. Beanstalk PaaS, EC2 IaaS …

> Or databased (DynamoDB, RDS...)

Page 38: Nanoservices and Microservices with Java

OSGi

Page 39: Nanoservices and Microservices with Java

OSGi: Bundles

> Partition system into – "bundles”

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

> ...at runtime

Page 40: Nanoservices and Microservices with Java

OSGi: Code Sharing

> Bundles can export and import packages

> Updating code requires other bundles to start fresh

Page 41: Nanoservices and Microservices with Java

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 42: Nanoservices and Microservices with Java

CallingBundle

Bundle (interfacecode)

Bundle(implementation

and service)

Service

Package(interface

code)

Package(interface

code)

Update to servicein running application

Page 43: Nanoservices and Microservices with Java

(Almost)Independent

Deployment Units

Page 44: Nanoservices and Microservices with Java

Java EE

Page 45: Nanoservices and Microservices with Java

Java EE

> JARs e.g. for EJBs

> WARs e.g. for web application

> EARs for JARs and WARs

> Completely separated code

> …unlike OSGi

Page 46: Nanoservices and Microservices with Java

Java EE

> Relevant: Deployment model

> i.e. application server

> Not programming model

Page 47: Nanoservices and Microservices with Java

Java EE Nanoservices?

> Local calls not possible

> No shared code e.g. for interfaces

Page 48: Nanoservices and Microservices with Java

Tomcat Java EEServer

order.war

customer.war

catalog.warCustomer

Page 49: Nanoservices and Microservices with Java

(Almost)Independent

Deployment Units

Page 50: Nanoservices and Microservices with Java

Comparison

Page 51: Nanoservices and Microservices with Java

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 52: Nanoservices and Microservices with Java

Benefits of Nanoservices

Page 53: Nanoservices and Microservices with Java

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 54: Nanoservices and Microservices with Java

Cost per Service

> Hardware, software cost

> Amazon Lambda: ++

> OSGi: ++

> Java EE: ++

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

Page 55: Nanoservices and Microservices with Java

Local Communcation

> Call without network stack

> Docker Fat JAR : --

> Amazon Lambda: --

> OSGi: ++

> Java EE: --

Page 56: Nanoservices and Microservices with Java

Challenges of Nanoservices

Page 57: Nanoservices and Microservices with Java

Independent Scaling

> Start more instances of a single service

> Docker Fat JAR: ++

> Amazon Lambda: ++

> OSGi: ?

> Java EE: --

Page 58: Nanoservices and Microservices with Java

Isolation

> CPU / Memory consumption/crash influences other services

> Docker Fat JAR: ++

> Amazon Lambda: ++

> OSGi: --

> Java EE: --

Page 59: Nanoservices and Microservices with Java

Resilience & Isolation

> Resilience: System can handle crash of other services

> Needs isolation

> Problem for OSGi/Java EE

Page 60: Nanoservices and Microservices with Java

Technology Freedom

> Using different technologies

> Docker Fat JAR: ++ (whatever)

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

> OSGi: -- (Java)

> Java EE: -- (Java)

Page 61: Nanoservices and Microservices with Java

Conclusion

Page 62: Nanoservices and Microservices with Java

Nanoservices!=Microservices

Page 63: Nanoservices and Microservices with Java

Nanoservices<Microservices

Page 64: Nanoservices and Microservices with Java

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 65: Nanoservices and Microservices with Java

Conclusion

> OSGi and Java EE weak concerning

> Independent scaling

> Isolation

> Technology freedom

> Amazon Lambda a lot stronger

Page 66: Nanoservices and Microservices with Java

Might also consider…

> Vert.x: polyglot, distributed and module concept

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

Page 67: Nanoservices and Microservices with Java

Thank You!

@ewolff

http://microservices-buch.de/

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

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