SlideShare a Scribd company logo
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
Ratpack and Grails 3 GR8Conf US 2014
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
Ratpack and Grails 3 GR8Conf US 2014
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

PPTX
Performance tuning Grails Applications GR8Conf US 2014
PPTX
Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014
PDF
Ratpack and Grails 3
PDF
Full Stack Reactive In Practice
PDF
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
PPTX
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
PDF
A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...
PDF
The 6 Rules for Modernizing Your Legacy Java Monolith with Microservices
Performance tuning Grails Applications GR8Conf US 2014
Ratpack and Grails 3 (and Spring Boot) SpringOne 2GX 2014
Ratpack and Grails 3
Full Stack Reactive In Practice
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...
The 6 Rules for Modernizing Your Legacy Java Monolith with Microservices

What's hot (19)

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

Viewers also liked (6)

DOC
Report Of Follow Up Week With Stakeholders
PPT
Secraterate
PPTX
Digital course
ZIP
Iec Ashok
PPTX
MARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel Willems
DOC
Cooperative Training 20 20 02 09 New
Report Of Follow Up Week With Stakeholders
Secraterate
Digital course
Iec Ashok
MARCOM 2013, Online strategie bepalen, hoe doe je dat? - Roel Willems
Cooperative Training 20 20 02 09 New
Ad

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

PDF
Ratpack and Grails 3
PDF
Microservices Architecture
PDF
GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3
PDF
Microservices and the Art of Taming the Dependency Hell Monster
PDF
Adopting Grails - GR8Conf Europe
PDF
GR8Conf 2011: Adopting Grails
PDF
Microservices - opportunities, dilemmas and problems
PDF
µServices Architecture @ EPAM WOW 2015
PDF
Java Edge.2009.Grails.Web.Dev.Made.Easy
PPTX
Microservices vs monolithics betabeers
PPTX
Microservices: The Right Way
PDF
Grails 101
PDF
Service-Oriented Design and Implement with Rails3
PPTX
Microservices architecture
PDF
Groovy - Grails as a modern scripting language for Web applications
PPTX
Yotpo microservices
PDF
Full lifecycle of a microservice
PDF
SOA Latam 2015
PDF
Microservice pitfalls
PPTX
Introduction to Grails 2013
Ratpack and Grails 3
Microservices Architecture
GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3
Microservices and the Art of Taming the Dependency Hell Monster
Adopting Grails - GR8Conf Europe
GR8Conf 2011: Adopting Grails
Microservices - opportunities, dilemmas and problems
µServices Architecture @ EPAM WOW 2015
Java Edge.2009.Grails.Web.Dev.Made.Easy
Microservices vs monolithics betabeers
Microservices: The Right Way
Grails 101
Service-Oriented Design and Implement with Rails3
Microservices architecture
Groovy - Grails as a modern scripting language for Web applications
Yotpo microservices
Full lifecycle of a microservice
SOA Latam 2015
Microservice pitfalls
Introduction to Grails 2013

Recently uploaded (20)

PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
medical staffing services at VALiNTRY
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
history of c programming in notes for students .pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPT
Introduction Database Management System for Course Database
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
top salesforce developer skills in 2025.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
CHAPTER 2 - PM Management and IT Context
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
medical staffing services at VALiNTRY
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
history of c programming in notes for students .pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Introduction Database Management System for Course Database
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Understanding Forklifts - TECH EHS Solution
Adobe Illustrator 28.6 Crack My Vision of Vector Design
top salesforce developer skills in 2025.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
ai tools demonstartion for schools and inter college
Softaken Excel to vCard Converter Software.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
How to Migrate SBCGlobal Email to Yahoo Easily
CHAPTER 2 - PM Management and IT Context

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
  • 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
  • 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"