Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Microservice Definition

Slide 5

Slide 5 text

Server Server Microservices: Definition > Independent deployment units > Separate VM / process > Any technology > Any infrastructure Micro Service Micro Service

Slide 6

Slide 6 text

Microservices= Independent Deployment Units

Slide 7

Slide 7 text

Components Collaborate Micro Service Micro Service Link Data Replication REST Messaging

Slide 8

Slide 8 text

Online Shop Order Catalog Search Billing Customer HTML / HTTP

Slide 9

Slide 9 text

Online Shop Elasticsearch Spring Batch Oracle Spring MVC MongoDB Order Catalog Search Billing

Slide 10

Slide 10 text

Microservices Stack

Slide 11

Slide 11 text

Docker > Linux (soon Windows) > Shared kernel > Filesystem just stores diffs > Extremely light weight > Can run in cluster (e.g. Kubernetes, Mesosphere etc)

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Microservice = Fat JAR + Java EE programming model possible!

Slide 14

Slide 14 text

Ideal size of a Microservice Team size Modularization Infrastructure Distributed Communication No absolute value! Replaceability Microservice Size

Slide 15

Slide 15 text

Nanoservices

Slide 16

Slide 16 text

Nanoservices?

Slide 17

Slide 17 text

Nanoservices? #SRSLY?

Slide 18

Slide 18 text

#SRSLY? YES!

Slide 19

Slide 19 text

Nanoservices!= Microservices

Slide 20

Slide 20 text

Nanoservices< Microservices

Slide 21

Slide 21 text

Ideal size of a Microservice Team size Modularization Infrastructure Distributed Communication No absolute value! Replaceability Microservice Size

Slide 22

Slide 22 text

Microservices= Independent Deployment Units

Slide 23

Slide 23 text

Nanoservices= Independent Deployment Units

Slide 24

Slide 24 text

Nanoservices use more light weight technologies

Slide 25

Slide 25 text

Amazon Lambda

Slide 26

Slide 26 text

Amazon Lambda > Service in the Amazon Cloud > Allows you to install individual functions > Java, JavaScript, Python

Slide 27

Slide 27 text

Lambda Function Command Line S3 Event Kinesis Stream DynamoDB SNS: Simple Notification Service SES: Simple EMail Service Cognito CloudWatch CloudFormation API Gateway (e.g. REST) Scheduled Events

Slide 28

Slide 28 text

Amazon Lambda adds e.g. trigger to DynamoDB.

Slide 29

Slide 29 text

Amazon Lambda + API Gateway = REST services.

Slide 30

Slide 30 text

public class Main { public String myHandler(int myCount, Context context) { LambdaLogger logger = context.getLogger(); logger.log("received : " + myCount); return "Hi"+myCount; } }

Slide 31

Slide 31 text

Deploy

Slide 32

Slide 32 text

Deploy

Slide 33

Slide 33 text

Invoke

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Amazon Lambda > Can add any other Amazon Service to complete the system > i.e. Beanstalk PaaS, EC2 IaaS … > Or databased (DynamoDB, RDS...)

Slide 38

Slide 38 text

OSGi

Slide 39

Slide 39 text

OSGi: Bundles > Partition system into – "bundles” > Bundles can be installed, started, stopped, uninstalled and updated > ...at runtime

Slide 40

Slide 40 text

OSGi: Code Sharing > Bundles can export and import packages > Updating code requires other bundles to start fresh

Slide 41

Slide 41 text

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 OSGi Declarative Services

Slide 42

Slide 42 text

Calling Bundle Bundle (interface code) Bundle (implementation and service) Service Package (interface code) Package (interface code) Update to service in running application

Slide 43

Slide 43 text

(Almost) Independent Deployment Units

Slide 44

Slide 44 text

Java EE

Slide 45

Slide 45 text

Java EE > JARs e.g. for EJBs > WARs e.g. for web application > EARs for JARs and WARs > Completely separated code > …unlike OSGi

Slide 46

Slide 46 text

Java EE > Relevant: Deployment model > i.e. application server > Not programming model

Slide 47

Slide 47 text

Java EE Nanoservices? > Local calls not possible > No shared code e.g. for interfaces

Slide 48

Slide 48 text

Tomcat Java EE Server order.war customer.war catalog.war Customer

Slide 49

Slide 49 text

(Almost) Independent Deployment Units

Slide 50

Slide 50 text

Comparison

Slide 51

Slide 51 text

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?

Slide 52

Slide 52 text

Benefits of Nanoservices

Slide 53

Slide 53 text

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)

Slide 54

Slide 54 text

Cost per Service > Hardware, software cost > Amazon Lambda: ++ > OSGi: ++ > Java EE: ++ > Docker Fat JAR: -- (need Docker container etc, separat JVM Heap)

Slide 55

Slide 55 text

Local Communcation > Call without network stack > Docker Fat JAR : -- > Amazon Lambda: -- > OSGi: ++ > Java EE: --

Slide 56

Slide 56 text

Challenges of Nanoservices

Slide 57

Slide 57 text

Independent Scaling > Start more instances of a single service > Docker Fat JAR: ++ > Amazon Lambda: ++ > OSGi: ? > Java EE: --

Slide 58

Slide 58 text

Isolation > CPU / Memory consumption/crash influences other services > Docker Fat JAR: ++ > Amazon Lambda: ++ > OSGi: -- > Java EE: --

Slide 59

Slide 59 text

Resilience & Isolation > Resilience: System can handle crash of other services > Needs isolation > Problem for OSGi/Java EE

Slide 60

Slide 60 text

Technology Freedom > Using different technologies > Docker Fat JAR: ++ (whatever) > Amazon Lambda: + (Java, JavaScript, Python) > OSGi: -- (Java) > Java EE: -- (Java)

Slide 61

Slide 61 text

Conclusion

Slide 62

Slide 62 text

Nanoservices!= Microservices

Slide 63

Slide 63 text

Nanoservices< Microservices

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

Conclusion > OSGi and Java EE weak concerning > Independent scaling > Isolation > Technology freedom > Amazon Lambda a lot stronger

Slide 66

Slide 66 text

Might also consider… > Vert.x: polyglot, distributed and module concept > Erlang: support update to running system and processes in other languages

Slide 67

Slide 67 text

Thank You! @ewolff http://microservices-buch.de/ http://microservices-book.com/primer.html http://aws.amazon.com/lambda/getting-started/