Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Microservice Definition

Slide 6

Slide 6 text

Microservices: Definition > No consistent definition > Microservices are modules > Independent deployment units > E.g. processes, Docker container > Microservice owned by one team

Slide 7

Slide 7 text

Microservices: Definition Server / Container Server / Container Micro Service Micro Service

Slide 8

Slide 8 text

Components Collaborate Micro Service Micro Service Link Data Replication REST Messaging

Slide 9

Slide 9 text

Online Shop Order Catalog Search Billing Customer HTML / HTTP

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Microservices Stack

Slide 12

Slide 12 text

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

Slide 13

Slide 13 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 14

Slide 14 text

Microservice = Fat JAR + Java EE programming model possible!

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Nanoservices

Slide 17

Slide 17 text

Nanoservices?

Slide 18

Slide 18 text

Nanoservices? #SRSLY?

Slide 19

Slide 19 text

#SRSLY? YES!

Slide 20

Slide 20 text

Nanoservices!= Microservices

Slide 21

Slide 21 text

Nanoservices< Microservices

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Microservices= Independent Deployment Units

Slide 24

Slide 24 text

Nanoservices= Independent Deployment Units

Slide 25

Slide 25 text

Nanoservices use more light weight technologies

Slide 26

Slide 26 text

Serverless

Slide 27

Slide 27 text

Serverless > Deploy a function > Pay per call > Example: Amazon Lambda > Similar: Google Cloud Functions > Azure Functions > IBM OpenWhisk (Open Source)

Slide 28

Slide 28 text

Serverless vs. PaaS

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

Amazon Lambda vs. 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

Slide 31

Slide 31 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 32

Slide 32 text

Amazon Lambda adds e.g. trigger to DynamoDB.

Slide 33

Slide 33 text

Amazon Lambda + API Gateway = REST services.

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Deploy

Slide 36

Slide 36 text

Deploy

Slide 37

Slide 37 text

Deploy

Slide 38

Slide 38 text

Deploy

Slide 39

Slide 39 text

Deploy

Slide 40

Slide 40 text

Deploy

Slide 41

Slide 41 text

Deploy

Slide 42

Slide 42 text

Invoke

Slide 43

Slide 43 text

Invoke

Slide 44

Slide 44 text

Invoke

Slide 45

Slide 45 text

Invoke

Slide 46

Slide 46 text

Invoke

Slide 47

Slide 47 text

Invoke

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

Send out slides via email!

Slide 52

Slide 52 text

Lambda Function Simple Email Service SMTP Simple Email Service Event calls Audience Cost: SES 0,10$ per 1000 EMails Lambda free

Slide 53

Slide 53 text

> Developed in Python > In the browser > ”Save & test” > Includes monitoring & alarm > Setting up SES was the hardest part…

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

OSGi

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 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 59

Slide 59 text

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

Slide 60

Slide 60 text

(Almost) Independent Deployment Units

Slide 61

Slide 61 text

Java EE

Slide 62

Slide 62 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 63

Slide 63 text

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

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

(Almost) Independent Deployment Units

Slide 67

Slide 67 text

Comparison

Slide 68

Slide 68 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 69

Slide 69 text

Benefits of Nanoservices

Slide 70

Slide 70 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 71

Slide 71 text

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

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

Challenges of Nanoservices

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

Conclusion

Slide 79

Slide 79 text

Nanoservices!= Microservices

Slide 80

Slide 80 text

Nanoservices< Microservices

Slide 81

Slide 81 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 82

Slide 82 text

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

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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