grails monolith to microservice to faas

Post on 12-Apr-2017

124 Views

Category:

Documents

6 Downloads

Preview:

Click to see full reader

TRANSCRIPT

GRAILS MONOLITH TO MICROSERVICE TO FAASCreated by / Michael Wyszinski @MikeWyszinski

ABOUT MECoding professionally since 1997...Grails user/fan since 2009-ishPrincipal Architect@WestconComstor

OVERVIEWWhy this topic?Our Grails ApplicationMicroservice & FaaS ArchitectureFaaS DemoGrails monolith -> MicroservicesGrails monolith -> FaaSConclusion

OUR GRAILS "MONOLITH" - HISTORYStarted life in 2007 using proprietary javaspace basedarchitecture... In 2013, ported to grails 2.x over 6 months...

Java Groovy JavaScript0

200k

400k

600k loc ­ pre­Grailsloc ­ Grails

We were also able to leverage the grails ecosystem: GORM,shiro plugin, audit plugin, dbmigration etc..

Our Team ♥'s Grails!

OUR GRAILS "MONOLITH" - FEATURESSaaS, cloud service brokerageQuote, Order, Manage, Bill many cloud products via asingle applicationGlobal tenant baseTenants are: internal users, resellers, vendors, end-customersCustom code per tenant

OUR GRAILS "MONOLITH" - COMPONENTSComponent Description Artefact

core shared "core": 67 domain classes, 66 services, multi-tenancy plugin, audit plugin, etc

JAR

api REST API WAR

backend runs async jobs (order processing & provisioning, etc)triggered by rabbitMQ messages

WAR

shell run custom shell scripts manually/cron N/A

portal angularjs portal for all users/tenants TAR

admin-ui semi auto-generated grails MVC app for internal powerusers(to be decommisioned)

WAR

WHAT ARE MICROSERVICES?“In short, the microservice architectural style

[1] is an approach to developing a singleapplication as a suite of small services, each

running in its own process andcommunicating with lightweight mechanisms,

often an HTTP resource API. These servicesare built around business capabilities and

independently deployable by fully automateddeployment machinery.”

- martinfowler.com

DEVELOPING MICROSERVICESscaling unit: per μ-serviceconcurrency: developer de�neddeployment: developer de�nedinfrastructure: devops managed

WHAT IS SERVERLESS/FAAS?“Serverless can also mean applications where some

amount of server-side logic is still written by theapplication developer but unlike traditional architectures

is run in stateless compute containers that are event-triggered, ephemeral (may only last for one invocation),

and fully managed by a 3rd party.

One way to think of this is ‘Functions as a service / FaaS”- martinfowler.com

servers DO exist. ...However, they are not accessible todevelopers, hence "serverless"

IAAS/CAAS/PAAS/FAAS

Source - https://www.voxxed.com/blog/2016/12/serverless-faas-aws-lambda-java/

ALL FAAS PLATFORMS......implement smallest possible μ-service -> f(x) = y...are event-driven (platform speci�c events)...have an HTTP API event trigger...support multiple f(x) runtimes (jvm, python, nodejs, c#, go,etc)...disposable runtime env instanciated per f(x) invocation...runtime env resources (RAM/CPU) con�gurable per f(x)

FAAS PROVIDERSONLY HOSTED

Amazon AWS LambdaMicrosoft Azure FunctionsGoogle Cloud Functions+ many others...

OPEN SOURCE

IBM OpenWhiskhttps://funktion.fabric8.io/https://github.com/b�rsh/serverless-docker + more all thetime...

FAAS HELLOWORLD DEMO!

HELLOWORLD - BUILD apply plugin: 'java' apply plugin: 'groovy'

repositories { mavenCentral() }

sourceCompatibility = 1.8 targetCompatibility = 1.8

dependencies { compile ( 'org.codehaus.groovy:groovy-all:2.4.7', 'com.amazonaws:aws-lambda-java-core:1.1.0', 'com.amazonaws:aws-lambda-java-log4j:1.0.0', 'com.fasterxml.jackson.core:jackson-core:2.8.5', 'com.fasterxml.jackson.core:jackson-databind:2.8.5',

HELLOWORLD - CONFIG service: groovy-hello

provider: name: aws runtime: java8 memorySize: 512 cfLogs: true

package: artifact: build/distributions/hello.zip

functions: hello: handler: com.serverless.HelloWorldHandler events: - http: path: helloworld

HELLOWORLD - HANDLERpackage com.helloworld

class HelloWorldHandler implements RequestHandler<Map<String, Object>, ApiGatewayResponse

@Override public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) { LOG.info("received: " + input);

//Process the request

Response responseBody = new Response("HelloWorld!", input);

return ApiGatewayResponse.builder() .setStatusCode(200) .setObjectBody(responseBody) .build(); } }

DEVELOPING FAASscaling unit: f(x)

concurrency: f(x), "in�nite" *

deployment: f(x)infrastructure: platform provided

FAAS CAVEATSLatency: Cold start timesHosted Limits: deployed code size, execution time limits,concurrent invocs, etc

EXAMPLE LIMITS - AWS LAMBDA

FAAS COSTSTraf�c Patterns Determines "Raw" savingsEf�ciency Gains; Maintenance & Ops not re�ected in Bill"in�nite" scale! in�nitly large bill during DDOS?

SERVERLESSCALC.COM

Calculating cost for AWS Lambda, AzureFunctions, Google Cloud Functions, and IBMOpenWhisk

Number of Executions

Estimated Execution Time (ms)

Serverless CostCalculator (beta)

Serverless Cost

Calculator

Peter Sbarski and

the A Cloud Guru

Team.

Grab our book

Number

of

Executions

© Peter Sbarski (A Cloud Guru)

Design: HTML5 UP

GRAILS MONOLITH -> MICROSERVICE1. refactor: shared domain + api + backend projects into...

N-deployable artefacts along business functions(OrderService, QuoteService, etc)Artefacts could contain both REST & async jobs

2. that's pretty much it...3. plugins? shared domains? versioning eveything..

GRAILS MONOLITH -> FAASgrails create-app my-faas --profile rest-api cd my-faas grails create-domain-class foo grails grails generate-all my.faas.Foo grails prod war

ls -lh build/libs/hello-faas-0.1.war -rw-r--r-- 1 mike staff 60M Jan 2 00:23 build/libs/hello-faas-0.1.war

1. Remove dependencies to shrink lib < 50MB2. no tomcat...3. found mock! https://github.com/bleshik/aws-lambda-servlet4. refactor to mock servlet container

wait. does grails behavior depend on servlet lifecycle?grails application context?do plugins I'm using depend on servlet lifecycle?

5. felt like a lot of more investigation required...

TAKEAWAYFaaS now provides functionality that overlaps with Grails(and prob most frameworks...)Tomcat replaced by API gateway ✘API gateways provide caching, SSL term, auth, SSO, etc...Not trivial to port Grails(and prob most frameworks) toFaaS

INTERESTING FAAS FEATURESIsolated runtime env -> f(x) dont compete for sharedheap/cpuConcurrency, programming model can be single threaded.....but, shared resources (DBs,etc) still need to handleconcurrent loadasync io?Disposable runtime env -> run untrusted code

FINAL REMARKSGrails Monolith to Microservices? :-)Grails Monolith to FaaS? Prob Not Impossible.Grails Still rocks ;-)

“ 1. Almost all the successful microservicestories have started with a monolith that got

too big and was broken up 2. Almost all the cases where I've heard of a

system that was built as a microservicesystem from scratch, it has ended up in serious

trouble. ”- martinfowler.com

THANKS

top related