SlideShare a Scribd company logo
1 of 25
Ratpack and Grails 3
Lari Hotari @lhotari
Pivotal Software, Inc.
Agenda
• Grails 3 and Ratpack
• Why async?
• Modularity and micro service architectures
• Embrace Gradle
• Abstract packaging / deployment
• Reach outside the servlet container
• App profiles: Netty, Servlet, Batch, Hadoop
• Lightweight deployments, support micro services
Grails 3
Why Netty / Ratpack?
Why async?
Amdahl's law
Little's law
• What does Little's law tell us when we are using
the thread-per-request model?
MeanNumberInSystem = MeanThroughput * MeanResponseTime
→
MeanThroughput = MeanNumberInSystem / MeanResponseTime
L = λW
Programming model
• Declarative programming expresses the logic of
a computation without describing its control flow.
• It's programming without the call stack, the
programmer doesn't decide execution details.
• Examples: functional and reactive programming,
event / message based execution, distributed
parallel computation algorithms like
Map/Reduce
16 import ratpack.session.SessionModule
17 import ratpack.session.store.MapSessionsModule
18 import ratpack.session.store.SessionStorage
19
20 import static ratpack.groovy.Groovy.groovyTemplate
21 import static ratpack.groovy.Groovy.ratpack
22 import static ratpack.jackson.Jackson.json
23 import static ratpack.pac4j.internal.SessionConstants.USER_PROFILE
24
25 ratpack {
26 bindings {
27 bind DatabaseHealthCheck
28 add new CodaHaleMetricsModule().jvmMetrics().jmx().websocket().
29 healthChecks()
30 add new HikariModule([URL: "jdbc:h2:mem:dev;INIT=CREATE SCHEMA IF NOT
31 EXISTS DEV"], "org.h2.jdbcx.JdbcDataSource")
32 add new SqlModule()
33 add new JacksonModule()
34 add new BookModule()
35 add new RemoteControlModule()
36 add new SessionModule()
37 add new MapSessionsModule(10, 5)
38 add new Pac4jModule<>(new FormClient("/login", new
39 SimpleTestUsernamePasswordAuthenticator()), new
40 AuthPathAuthorizer())
41
42 init { BookService bookService ->
43 RxRatpack.initialize()
44 HystrixRatpack.initialize()
45 bookService.createTable()
46 }
47 }
48
49 handlers { BookService bookService ->
50
51 get {
52 bookService.all().toList().subscribe { List<Book> books ->
53 SessionStorage sessionStorage = request.get(SessionStorage)
54 UserProfile profile = sessionStorage.get(USER_PROFILE)
55 def username = profile?.getAttribute("username")
56
57 render groovyTemplate("listing.html",
58 username: username ?: "",
59 title: "Books",
60 books: books,
61 msg: request.queryParams.msg ?: "")
62 }
63 }
64
65 handler("create") {
66 byMethod {
67 get {
68 render groovyTemplate("create.html", title: "Create Book")
69 }
70 post {
71 Form form = parse(Form)
72 bookService.insert(
73 form.isbn,
74 form.get("quantity").asType(Long),
75 form.get("price").asType(BigDecimal)
76 ).single().subscribe { String isbn ->
77 redirect "/?msg=Book+$isbn+created"
78 }
79 }
80 }
81 }
82
83 handler("update/:isbn") {
84 def isbn = pathTokens["isbn"]
85
86 bookService.find(isbn).single().subscribe { Book book ->
87 if (book == null) {
88 clientError(404)
89 } else {
90 byMethod {
91 get {
92 render groovyTemplate("update.html", title:
93 "Update Book", book: book)
94 }
95 post {
96 Form form = parse(Form)
97 bookService.update(
98 isbn,
99 form.get("quantity").asType(Long),
100 form.get("price").asType(BigDecimal)
101 ) subscribe {
102 redirect "/?msg=Book+$isbn+updated"
103 }
104 }
105 }
106 }
107 }
108 }
109
110 post("delete/:isbn") {
111 def isbn = pathTokens["isbn"]
112 bookService.delete(isbn).subscribe {
113 redirect "/?msg=Book+$isbn+deleted"
114 }
115 }
116
117 prefix("api") {
118 get("books") {
119 bookService.all().toList().subscribe { List<Book> books ->
120 render json(books)
121 }
122 }
80 }
81 }
82
83 handler("update/:isbn") {
84 def isbn = pathTokens["isbn"]
85
86 bookService.find(isbn).single().subscribe { Book book ->
87 if (book == null) {
88 clientError(404)
89 } else {
90 byMethod {
91 get {
92 render groovyTemplate("update.html", title:
93 "Update Book", book: book)
94 }
95 post {
96 Form form = parse(Form)
97 bookService.update(
98 isbn,
99 form.get("quantity").asType(Long),
100 form.get("price").asType(BigDecimal)
101 ) subscribe {
102 redirect "/?msg=Book+$isbn+updated"
103 }
104 }
105 }
106 }
107 }
108 }
109
110 post("delete/:isbn") {
111 def isbn = pathTokens["isbn"]
source: https://github.com/ratpack/example-books/blob/master/src/ratpack/Ratpack.groovy
Ratpack application
consists of functional
handler chains
Ratpack applications
• Ratpacks comes with Guice for dependency injection
• Guice modules are also used as the plugin system for
Ratpack
• Examples of Ratpack module contributions:
• Integrations to RxJava and Reactor. Can be used for
async composition and preventing "callback hell".
• Integration to Netflix Hystrix for adding error resilience
functionality . f.e., Circuit-breaker pattern impl.
Demo
Ratpack and Grails (GORM) used together
• https://github.com/lhotari/ratpack-gorm-example
• Spring Boot embedded in Ratpack, running
GORM
Modularity
• logical partitioning of the "software design"
• allows complex software to be manageable for
the purpose of implementation and maintenance
Coupling and Cohesion
• Coupling and cohesion are measures for
describing how easy it will be to change the
behaviour of some element in a system
• Modules are coupled if a change in one forces a
change in a the other
• A module's cohesion is a measure of whether it's
responsibilities form a meaningful unit
source: GOOS book
• Low coupling between modules ⟹ easier to
change
• High cohesion within module ⟹ single
responsibility
Microservice definition
by James Lewis
• Each application only does one thing
• Small enough to fit in your head
• Small enough that you can throw them away
• Embedded web container
• Packaged as a single executable jar
• Use HTTP and HATEOAS to decouple services
• Each app exposes metrics about itself
–Arnon Rotem-Gal-Oz, Practical SOA
“Nanoservice is an Anti-pattern where a
service is too fine grained. Nanoservice is a
service whose overhead (communications,
maintenance etc.) out-weights its utility.”
Polyglot persistence
• Common principle is that each service owns it's data -
there is no shared database across multiple services.
• If this principle is followed, it usually means switching to
Hexagonal architecture, where persistence is an
integration and not part of the core.
• "Start with the events and behaviour instead of the
database."
• Data consistency models in distributed systems
Brooks: "No silver
bullet"
• Essential complexity
• complexity that you cannot escape
• Accidental complexity
• we could be adding complexity by bad design
- Google's "Solve for X"
“You don't spend your time
being bothered that you can't
teleport from here to Japan,
because there's a part of you
that thinks it's impossible.
Moonshot thinking is choosing
to be bothered by that.”
Modular monoliths
• Modular monoliths are composed of loosely coupled
modules of single responsibility
• Enabling the 3rd way (after monoliths and
microservices) for building applications on the JVM
across different libraries and frameworks
• Modules can be turned into true micro services when
needed - instead of introducing accidental complexity
to projects that don't really require micro services in the
beginning, but could benefit of them later
The monoliths in the micro
services architecture
Single Page
App in
Browser
API Gateway
service
µservic
e A
SAAS
Service A
SAAS
Service B
µservic
e B
µservic
e C
µservic
e D
µservic
e E
µservic
e F
"If you built it..."
pretotyping.org
“Make sure you are building the
right it before you build it right."
"Fail fast ... and Often"
Thanks!
Lari Hotari @lhotari
Pivotal Software, Inc.

More Related Content

What's hot

Digital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and MicroservicesDigital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and MicroservicesLightbend
 
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...confluent
 
Machine Learning At Speed: Operationalizing ML For Real-Time Data Streams
Machine Learning At Speed: Operationalizing ML For Real-Time Data StreamsMachine Learning At Speed: Operationalizing ML For Real-Time Data Streams
Machine Learning At Speed: Operationalizing ML For Real-Time Data StreamsLightbend
 
Nine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youNine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youMarkus Eisele
 
Microservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got HereMicroservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got HereLightbend
 
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...Lightbend
 
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby AnandanPivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby AnandanPivotalOpenSourceHub
 
Hands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandHands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandC2B2 Consulting
 
War Stories: DIY Kafka
War Stories: DIY KafkaWar Stories: DIY Kafka
War Stories: DIY Kafkaconfluent
 
Cloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful ServerlessCloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful ServerlessLightbend
 
The Evolution of Distributed Systems on Kubernetes
The Evolution of Distributed Systems on KubernetesThe Evolution of Distributed Systems on Kubernetes
The Evolution of Distributed Systems on KubernetesBilgin Ibryam
 
Building Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
Building Reactive Fast Data & the Data Lake with Akka, Kafka, SparkBuilding Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
Building Reactive Fast Data & the Data Lake with Akka, Kafka, SparkTodd Fritz
 
KafkaConsumer - Decoupling Consumption and Processing for Better Resource Uti...
KafkaConsumer - Decoupling Consumption and Processing for Better Resource Uti...KafkaConsumer - Decoupling Consumption and Processing for Better Resource Uti...
KafkaConsumer - Decoupling Consumption and Processing for Better Resource Uti...confluent
 
Organic Growth and A Good Night Sleep: Effective Kafka Operations at Pinteres...
Organic Growth and A Good Night Sleep: Effective Kafka Operations at Pinteres...Organic Growth and A Good Night Sleep: Effective Kafka Operations at Pinteres...
Organic Growth and A Good Night Sleep: Effective Kafka Operations at Pinteres...confluent
 
Tuning Java Driver for Apache Cassandra by Nenad Bozic at Big Data Spain 2017
Tuning Java Driver for Apache Cassandra by Nenad Bozic at Big Data Spain 2017Tuning Java Driver for Apache Cassandra by Nenad Bozic at Big Data Spain 2017
Tuning Java Driver for Apache Cassandra by Nenad Bozic at Big Data Spain 2017Big Data Spain
 
Running Apache Spark Jobs Using Kubernetes
Running Apache Spark Jobs Using KubernetesRunning Apache Spark Jobs Using Kubernetes
Running Apache Spark Jobs Using KubernetesDatabricks
 
Time Series Analysis Using an Event Streaming Platform
 Time Series Analysis Using an Event Streaming Platform Time Series Analysis Using an Event Streaming Platform
Time Series Analysis Using an Event Streaming PlatformDr. Mirko Kämpf
 

What's hot (19)

Digital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and MicroservicesDigital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and Microservices
 
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
 
Machine Learning At Speed: Operationalizing ML For Real-Time Data Streams
Machine Learning At Speed: Operationalizing ML For Real-Time Data StreamsMachine Learning At Speed: Operationalizing ML For Real-Time Data Streams
Machine Learning At Speed: Operationalizing ML For Real-Time Data Streams
 
Real-Time Design Patterns
Real-Time Design PatternsReal-Time Design Patterns
Real-Time Design Patterns
 
Nine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youNine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take you
 
Microservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got HereMicroservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got Here
 
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
 
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby AnandanPivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
 
Hands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandHands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx Poland
 
War Stories: DIY Kafka
War Stories: DIY KafkaWar Stories: DIY Kafka
War Stories: DIY Kafka
 
Cloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful ServerlessCloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful Serverless
 
The Evolution of Distributed Systems on Kubernetes
The Evolution of Distributed Systems on KubernetesThe Evolution of Distributed Systems on Kubernetes
The Evolution of Distributed Systems on Kubernetes
 
Building Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
Building Reactive Fast Data & the Data Lake with Akka, Kafka, SparkBuilding Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
Building Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
 
KafkaConsumer - Decoupling Consumption and Processing for Better Resource Uti...
KafkaConsumer - Decoupling Consumption and Processing for Better Resource Uti...KafkaConsumer - Decoupling Consumption and Processing for Better Resource Uti...
KafkaConsumer - Decoupling Consumption and Processing for Better Resource Uti...
 
Revitalizing Aging Architectures with Microservices
Revitalizing Aging Architectures with MicroservicesRevitalizing Aging Architectures with Microservices
Revitalizing Aging Architectures with Microservices
 
Organic Growth and A Good Night Sleep: Effective Kafka Operations at Pinteres...
Organic Growth and A Good Night Sleep: Effective Kafka Operations at Pinteres...Organic Growth and A Good Night Sleep: Effective Kafka Operations at Pinteres...
Organic Growth and A Good Night Sleep: Effective Kafka Operations at Pinteres...
 
Tuning Java Driver for Apache Cassandra by Nenad Bozic at Big Data Spain 2017
Tuning Java Driver for Apache Cassandra by Nenad Bozic at Big Data Spain 2017Tuning Java Driver for Apache Cassandra by Nenad Bozic at Big Data Spain 2017
Tuning Java Driver for Apache Cassandra by Nenad Bozic at Big Data Spain 2017
 
Running Apache Spark Jobs Using Kubernetes
Running Apache Spark Jobs Using KubernetesRunning Apache Spark Jobs Using Kubernetes
Running Apache Spark Jobs Using Kubernetes
 
Time Series Analysis Using an Event Streaming Platform
 Time Series Analysis Using an Event Streaming Platform Time Series Analysis Using an Event Streaming Platform
Time Series Analysis Using an Event Streaming Platform
 

Viewers also liked

Report Of Follow Up Week With Stakeholders
Report Of Follow Up Week With StakeholdersReport Of Follow Up Week With Stakeholders
Report Of Follow Up Week With Stakeholdersguesta4ad22e3
 
Digital course
Digital courseDigital course
Digital courseimgaurav
 
MARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel Willems
MARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel WillemsMARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel Willems
MARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel WillemsRoel Willems
 
Cooperative Training 20 20 02 09 New
Cooperative Training 20 20 02 09  NewCooperative Training 20 20 02 09  New
Cooperative Training 20 20 02 09 Newguesta4ad22e3
 

Viewers also liked (6)

Report Of Follow Up Week With Stakeholders
Report Of Follow Up Week With StakeholdersReport Of Follow Up Week With Stakeholders
Report Of Follow Up Week With Stakeholders
 
Secraterate
SecraterateSecraterate
Secraterate
 
Digital course
Digital courseDigital course
Digital course
 
Iec Ashok
Iec AshokIec Ashok
Iec Ashok
 
MARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel Willems
MARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel WillemsMARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel Willems
MARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel Willems
 
Cooperative Training 20 20 02 09 New
Cooperative Training 20 20 02 09  NewCooperative Training 20 20 02 09  New
Cooperative Training 20 20 02 09 New
 

Similar to Ratpack and Grails 3 GR8Conf US 2014

Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3GR8Conf
 
Microservice message routing on Kubernetes
Microservice message routing on KubernetesMicroservice message routing on Kubernetes
Microservice message routing on KubernetesFrans van Buul
 
The hardest part of microservices: your data
The hardest part of microservices: your dataThe hardest part of microservices: your data
The hardest part of microservices: your dataChristian Posta
 
BISSA: Empowering Web gadget Communication with Tuple Spaces
BISSA: Empowering Web gadget Communication with Tuple SpacesBISSA: Empowering Web gadget Communication with Tuple Spaces
BISSA: Empowering Web gadget Communication with Tuple SpacesSrinath Perera
 
Exploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservicesExploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservices💡 Tomasz Kogut
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor FrameworkDamien Magoni
 
Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2Christian Posta
 
SpringPeople - Introduction to Cloud Computing
SpringPeople - Introduction to Cloud ComputingSpringPeople - Introduction to Cloud Computing
SpringPeople - Introduction to Cloud ComputingSpringPeople
 
Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"LogeekNightUkraine
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideMohanraj Thirumoorthy
 
Big Data_Architecture.pptx
Big Data_Architecture.pptxBig Data_Architecture.pptx
Big Data_Architecture.pptxbetalab
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice frameworkFabrice Sznajderman
 
PresentationPatterns_v2
PresentationPatterns_v2PresentationPatterns_v2
PresentationPatterns_v2Maksym Tolstik
 
Deploying Machine Learning Models with Pulsar Functions - Pulsar Summit Asia...
Deploying Machine Learning Models with Pulsar Functions  - Pulsar Summit Asia...Deploying Machine Learning Models with Pulsar Functions  - Pulsar Summit Asia...
Deploying Machine Learning Models with Pulsar Functions - Pulsar Summit Asia...StreamNative
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithmsiqbalphy1
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Storyvanphp
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive uiPaul van Zyl
 
Software variability management - 2017
Software variability management - 2017Software variability management - 2017
Software variability management - 2017XavierDevroey
 

Similar to Ratpack and Grails 3 GR8Conf US 2014 (20)

Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3
 
Microservice message routing on Kubernetes
Microservice message routing on KubernetesMicroservice message routing on Kubernetes
Microservice message routing on Kubernetes
 
The hardest part of microservices: your data
The hardest part of microservices: your dataThe hardest part of microservices: your data
The hardest part of microservices: your data
 
BISSA: Empowering Web gadget Communication with Tuple Spaces
BISSA: Empowering Web gadget Communication with Tuple SpacesBISSA: Empowering Web gadget Communication with Tuple Spaces
BISSA: Empowering Web gadget Communication with Tuple Spaces
 
AngularJS
AngularJSAngularJS
AngularJS
 
Exploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservicesExploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservices
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
 
Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2
 
SpringPeople - Introduction to Cloud Computing
SpringPeople - Introduction to Cloud ComputingSpringPeople - Introduction to Cloud Computing
SpringPeople - Introduction to Cloud Computing
 
Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Big Data_Architecture.pptx
Big Data_Architecture.pptxBig Data_Architecture.pptx
Big Data_Architecture.pptx
 
Jclouds Intro
Jclouds IntroJclouds Intro
Jclouds Intro
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice framework
 
PresentationPatterns_v2
PresentationPatterns_v2PresentationPatterns_v2
PresentationPatterns_v2
 
Deploying Machine Learning Models with Pulsar Functions - Pulsar Summit Asia...
Deploying Machine Learning Models with Pulsar Functions  - Pulsar Summit Asia...Deploying Machine Learning Models with Pulsar Functions  - Pulsar Summit Asia...
Deploying Machine Learning Models with Pulsar Functions - Pulsar Summit Asia...
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithms
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive ui
 
Software variability management - 2017
Software variability management - 2017Software variability management - 2017
Software variability management - 2017
 

Recently uploaded

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Ratpack and Grails 3 GR8Conf US 2014

  • 1. Ratpack and Grails 3 Lari Hotari @lhotari Pivotal Software, Inc.
  • 2. Agenda • Grails 3 and Ratpack • Why async? • Modularity and micro service architectures
  • 3. • Embrace Gradle • Abstract packaging / deployment • Reach outside the servlet container • App profiles: Netty, Servlet, Batch, Hadoop • Lightweight deployments, support micro services Grails 3
  • 4.
  • 5. Why Netty / Ratpack? Why async?
  • 7. Little's law • What does Little's law tell us when we are using the thread-per-request model? MeanNumberInSystem = MeanThroughput * MeanResponseTime → MeanThroughput = MeanNumberInSystem / MeanResponseTime L = λW
  • 8. Programming model • Declarative programming expresses the logic of a computation without describing its control flow. • It's programming without the call stack, the programmer doesn't decide execution details. • Examples: functional and reactive programming, event / message based execution, distributed parallel computation algorithms like Map/Reduce
  • 9. 16 import ratpack.session.SessionModule 17 import ratpack.session.store.MapSessionsModule 18 import ratpack.session.store.SessionStorage 19 20 import static ratpack.groovy.Groovy.groovyTemplate 21 import static ratpack.groovy.Groovy.ratpack 22 import static ratpack.jackson.Jackson.json 23 import static ratpack.pac4j.internal.SessionConstants.USER_PROFILE 24 25 ratpack { 26 bindings { 27 bind DatabaseHealthCheck 28 add new CodaHaleMetricsModule().jvmMetrics().jmx().websocket(). 29 healthChecks() 30 add new HikariModule([URL: "jdbc:h2:mem:dev;INIT=CREATE SCHEMA IF NOT 31 EXISTS DEV"], "org.h2.jdbcx.JdbcDataSource") 32 add new SqlModule() 33 add new JacksonModule() 34 add new BookModule() 35 add new RemoteControlModule() 36 add new SessionModule() 37 add new MapSessionsModule(10, 5) 38 add new Pac4jModule<>(new FormClient("/login", new 39 SimpleTestUsernamePasswordAuthenticator()), new 40 AuthPathAuthorizer()) 41 42 init { BookService bookService -> 43 RxRatpack.initialize() 44 HystrixRatpack.initialize() 45 bookService.createTable() 46 } 47 } 48 49 handlers { BookService bookService -> 50 51 get { 52 bookService.all().toList().subscribe { List<Book> books -> 53 SessionStorage sessionStorage = request.get(SessionStorage) 54 UserProfile profile = sessionStorage.get(USER_PROFILE) 55 def username = profile?.getAttribute("username") 56 57 render groovyTemplate("listing.html", 58 username: username ?: "", 59 title: "Books", 60 books: books, 61 msg: request.queryParams.msg ?: "") 62 } 63 } 64 65 handler("create") { 66 byMethod { 67 get { 68 render groovyTemplate("create.html", title: "Create Book") 69 } 70 post { 71 Form form = parse(Form) 72 bookService.insert( 73 form.isbn, 74 form.get("quantity").asType(Long), 75 form.get("price").asType(BigDecimal) 76 ).single().subscribe { String isbn -> 77 redirect "/?msg=Book+$isbn+created" 78 } 79 } 80 } 81 } 82 83 handler("update/:isbn") { 84 def isbn = pathTokens["isbn"] 85 86 bookService.find(isbn).single().subscribe { Book book -> 87 if (book == null) { 88 clientError(404) 89 } else { 90 byMethod { 91 get { 92 render groovyTemplate("update.html", title: 93 "Update Book", book: book) 94 } 95 post { 96 Form form = parse(Form) 97 bookService.update( 98 isbn, 99 form.get("quantity").asType(Long), 100 form.get("price").asType(BigDecimal) 101 ) subscribe { 102 redirect "/?msg=Book+$isbn+updated" 103 } 104 } 105 } 106 } 107 } 108 } 109 110 post("delete/:isbn") { 111 def isbn = pathTokens["isbn"] 112 bookService.delete(isbn).subscribe { 113 redirect "/?msg=Book+$isbn+deleted" 114 } 115 } 116 117 prefix("api") { 118 get("books") { 119 bookService.all().toList().subscribe { List<Book> books -> 120 render json(books) 121 } 122 } 80 } 81 } 82 83 handler("update/:isbn") { 84 def isbn = pathTokens["isbn"] 85 86 bookService.find(isbn).single().subscribe { Book book -> 87 if (book == null) { 88 clientError(404) 89 } else { 90 byMethod { 91 get { 92 render groovyTemplate("update.html", title: 93 "Update Book", book: book) 94 } 95 post { 96 Form form = parse(Form) 97 bookService.update( 98 isbn, 99 form.get("quantity").asType(Long), 100 form.get("price").asType(BigDecimal) 101 ) subscribe { 102 redirect "/?msg=Book+$isbn+updated" 103 } 104 } 105 } 106 } 107 } 108 } 109 110 post("delete/:isbn") { 111 def isbn = pathTokens["isbn"] source: https://github.com/ratpack/example-books/blob/master/src/ratpack/Ratpack.groovy Ratpack application consists of functional handler chains
  • 10. Ratpack applications • Ratpacks comes with Guice for dependency injection • Guice modules are also used as the plugin system for Ratpack • Examples of Ratpack module contributions: • Integrations to RxJava and Reactor. Can be used for async composition and preventing "callback hell". • Integration to Netflix Hystrix for adding error resilience functionality . f.e., Circuit-breaker pattern impl.
  • 11. Demo Ratpack and Grails (GORM) used together • https://github.com/lhotari/ratpack-gorm-example • Spring Boot embedded in Ratpack, running GORM
  • 12.
  • 13. Modularity • logical partitioning of the "software design" • allows complex software to be manageable for the purpose of implementation and maintenance
  • 14. Coupling and Cohesion • Coupling and cohesion are measures for describing how easy it will be to change the behaviour of some element in a system • Modules are coupled if a change in one forces a change in a the other • A module's cohesion is a measure of whether it's responsibilities form a meaningful unit source: GOOS book
  • 15. • Low coupling between modules ⟹ easier to change • High cohesion within module ⟹ single responsibility
  • 16. Microservice definition by James Lewis • Each application only does one thing • Small enough to fit in your head • Small enough that you can throw them away • Embedded web container • Packaged as a single executable jar • Use HTTP and HATEOAS to decouple services • Each app exposes metrics about itself
  • 17. –Arnon Rotem-Gal-Oz, Practical SOA “Nanoservice is an Anti-pattern where a service is too fine grained. Nanoservice is a service whose overhead (communications, maintenance etc.) out-weights its utility.”
  • 18. Polyglot persistence • Common principle is that each service owns it's data - there is no shared database across multiple services. • If this principle is followed, it usually means switching to Hexagonal architecture, where persistence is an integration and not part of the core. • "Start with the events and behaviour instead of the database." • Data consistency models in distributed systems
  • 19. Brooks: "No silver bullet" • Essential complexity • complexity that you cannot escape • Accidental complexity • we could be adding complexity by bad design
  • 20. - Google's "Solve for X" “You don't spend your time being bothered that you can't teleport from here to Japan, because there's a part of you that thinks it's impossible. Moonshot thinking is choosing to be bothered by that.”
  • 21. Modular monoliths • Modular monoliths are composed of loosely coupled modules of single responsibility • Enabling the 3rd way (after monoliths and microservices) for building applications on the JVM across different libraries and frameworks • Modules can be turned into true micro services when needed - instead of introducing accidental complexity to projects that don't really require micro services in the beginning, but could benefit of them later
  • 22. The monoliths in the micro services architecture Single Page App in Browser API Gateway service µservic e A SAAS Service A SAAS Service B µservic e B µservic e C µservic e D µservic e E µservic e F
  • 23. "If you built it..."
  • 24. pretotyping.org “Make sure you are building the right it before you build it right." "Fail fast ... and Often"