Download - Grails Monolith to Microservice to FaaS
![Page 1: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/1.jpg)
GRAILS MONOLITH TO MICROSERVICE TO FAASCreated by / Michael Wyszinski @MikeWyszinski
![Page 2: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/2.jpg)
ABOUT MECoding professionally since 1997...Grails user/fan since 2009-ishPrincipal Architect@WestconComstor
![Page 3: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/3.jpg)
OVERVIEWWhy this topic?Our Grails ApplicationMicroservice & FaaS ArchitectureFaaS DemoGrails monolith -> MicroservicesGrails monolith -> FaaSConclusion
![Page 4: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/4.jpg)
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 preGrailsloc Grails
We were also able to leverage the grails ecosystem: GORM,shiro plugin, audit plugin, dbmigration etc..
Our Team ♥'s Grails!
![Page 5: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/5.jpg)
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
![Page 6: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/6.jpg)
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
![Page 7: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/7.jpg)
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
![Page 8: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/8.jpg)
DEVELOPING MICROSERVICESscaling unit: per μ-serviceconcurrency: developer de�neddeployment: developer de�nedinfrastructure: devops managed
![Page 9: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/9.jpg)
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"
![Page 10: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/10.jpg)
IAAS/CAAS/PAAS/FAAS
Source - https://www.voxxed.com/blog/2016/12/serverless-faas-aws-lambda-java/
![Page 11: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/11.jpg)
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)
![Page 12: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/12.jpg)
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...
![Page 13: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/13.jpg)
FAAS HELLOWORLD DEMO!
![Page 14: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/14.jpg)
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',
![Page 15: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/15.jpg)
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
![Page 16: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/16.jpg)
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(); } }
![Page 17: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/17.jpg)
DEVELOPING FAASscaling unit: f(x)
concurrency: f(x), "in�nite" *
deployment: f(x)infrastructure: platform provided
![Page 18: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/18.jpg)
FAAS CAVEATSLatency: Cold start timesHosted Limits: deployed code size, execution time limits,concurrent invocs, etc
![Page 19: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/19.jpg)
EXAMPLE LIMITS - AWS LAMBDA
![Page 20: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/20.jpg)
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?
![Page 21: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/21.jpg)
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
![Page 22: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/22.jpg)
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..
![Page 23: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/23.jpg)
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...
![Page 24: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/24.jpg)
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
![Page 25: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/25.jpg)
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
![Page 26: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/26.jpg)
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
![Page 27: Grails Monolith to Microservice to FaaS](https://reader034.vdocuments.site/reader034/viewer/2022050900/58ed317d1a28abf90b8b4601/html5/thumbnails/27.jpg)
THANKS