ggx 2014 lari hotari modular monoliths with spring boot and grails 3

40
‹#› © 2014 Pivotal Software, Inc. All rights reserved. ‹#› © 2014 Pivotal Software, Inc. All rights reserved. Modular Monoliths with Grails 3 and Spring Boot Lari Hotari, Pivotal Software Inc. presentation recording: http://goo.gl/LRlrQK

Upload: lari-hotari

Post on 12-Jul-2015

1.167 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Modular Monoliths with Grails 3 and Spring BootLari Hotari, Pivotal Software Inc.

presentation recording:

http://goo.gl/LRlrQK

Page 2: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Pivotal Analytics

Page 3: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Agenda

• Modularity: Why? What? • How to approach the design of Modular Monoliths with

Grails 3 and Spring Boot? – current alternatives – challenges and drawbacks – future possibilities?

presentation recording:

http://goo.gl/LRlrQK

Page 4: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Page 5: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

What's the right way?

Page 6: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Microservices?

Page 7: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial l icense: http://creativecommons.org/licenses/by-nc/3.0/

Velocity is the Killer App

Page 8: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Conceptual graph of cost of change & time-to-value

connected monolith is cheaper in the beginning

cost per change is high, system replacement requires changes too

Cumulated number of changes / features

http://www.threeriversinstitute.org/blog/?p=338

Cost & time-to-value per additional feature/change

You can plan to switch strategies!

source: Kent Beck's blog post: To Design or Not To Design? A Third Good Question

Page 9: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Modularity

• logical partitioning of the software at design time • separation of concerns

• allows complex software to be manageable for the purpose of implementation and maintenance

Page 10: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

The challenge with using microservices architecture

http://www.infoq.com/articles/microservices-intro

Chris Richardson: Microservices: Decomposing Applications for Deployability and Scalability

In the beginning:

• You don't need it. • It will slow you down.

Later on:

• You need it. • Refactoring is painful.

“Because of these issues, adopting a microservice architecture should not be undertaken lightly.”

Page 11: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

http://martinfowler.com/bliki/SacrificialArchitecture.html

Page 12: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

What is the problem we are trying to solve?

Page 13: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Page 14: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Page 15: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Maintainability, not just modularity

• modularity • conceptual clarity and consistency • easy to learn and understand from developer's point of

view – it's very important that developers understand the story

that the elements of the system is telling (DDD blue book)

• as developers, we want to feel safe in doing changes to the system (safety net of tdd, etc.), easy to validate changes

Page 16: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

From Reuse to Replaceability

• earlier software reuse was one of the main goals • large legacy systems are hard to replace.

– stop building large monoliths!

Page 17: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

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

For a longer and better explanation, read Kent Beck's blog post on Coupling and Cohesion http://www.threeriversinstitute.org/blog/?p=104

Page 18: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Optimal Coupling and Cohesion within the Context

• Low coupling between modules ⟹ easier to change

• High cohesion within module ⟹ meaningful single responsibility

Page 19: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Coupling related guidelines

• Elements that change of the same reason should be kept together to minimise the ripple effects.

• Separate things that change at different rates.

Page 20: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Other types of coupling

• Be aware of behavioural or temporal coupling that is hidden and hard to detect: no static analysis can detect this type of coupling. • Shared mutable state related coupling

• coupling via shared database • transactions

• RPC • Your system can be extremely "clean" and technically

loosely coupled (at design time), but this doesn't really improve the situation in the end when there is tight behavioural or temporal coupling at runtime. => ripple effects, high cost of change

Page 21: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Brooks: "No silver bullet"

• Essential complexity – complexity that you cannot escape

• Accidental complexity – we could be adding complexity by bad design

Page 22: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Modularity of commonly used Spring/Grails application architectures styles

Page 23: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Sources of excess coupling in large Grails/Spring applications (applies to many others too)• There is a common misconception that shared layers are

good for modularity. Usually they aren't. "Vertical slices" should be also used. • see Oliver Gierke's presentation for better explanation

https://www.youtube.com/watch?v=tEm0USdF-70 • Accidental architecture. You should have a sound plan to

accomplish modularity and also enforce it. See Oliver's blog post: http://olivergierke.de/2013/01/whoops-where-did-my-architecture-go/

• Unnecessary coupling to implementation details in interfaces

• DRY at extremes causes coupling which reduces flexibility. • Tests cause coupling too since tests have to be maintained.

Page 24: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Grails plugins

• Grails plugins provide a way to decompose the application to vertical slices at design time.

Page 25: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Spring modularity related options

• Spring Boot applications can be decomposed in separate jar-modules as well. These "plugins" can be reused like Grails plugins.

• Spring bean contexts (configured with java config or xml) can be used to encapsulate groups of Spring beans to be packaged and reused as libraries in several applications.

• UI resources can be referenced from web jars • DI is providing a way to decouple implementation classes

from consumer classes. DI is also used to inject configuration parameters in Spring applications.

• Spring Boot Auto-Configuration for activating "starter" modules that are on the classpath. You can build your own "starter"/auto-configuration modules too.

Page 26: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Grails 3 apps are Spring Boot apps

• Since Grails 3 will be based on Spring Boot, the features of Spring Boot are useable in Grails 3 apps too.

• Grails 3 apps are Spring Boot apps with extended functionality to bring the developer similar behaviour and features as in previous Grails versions.

• Watch Graeme's keynote tomorrow for a demo and more information about Grails 3.

Page 27: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Presentation

Services

Persistence

Page 28: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Presentation

Services

Persistence

Account Search Order

Page 29: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Stefan Tilkov's Vertical Systems approach a.k.a Self Contained Systems

• Very small • 100s • Does one thing only • Separate client • No shared DB

• Medium sized • 10s • Small # of related things • Includes UI • No shared DB

Microservices approach Vertical Systems approach

http://www.infoq.com/presentations/modular-ecommerce-website

• You don't need any special frameworks or containers to implement the Self Contained Systems approach today. You usually need SSO and a way to make the UI consistent across the vertical slices. You don't need a portal server to do this.

Page 30: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Account

Presentation

Services

Persistence

Search Order

Presentation

Services

Persistence

Presentation

Services

Persistence

Page 31: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Gradually migrating to microservices?

Page 32: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Hybrid style - Microservices and Self Contained Systems strategy

Account

Presentation

Services

Persistence

Search

Presentation

Services

Persistence

Order

Presentation

Services

Persistence

Page 33: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Everything as a microservice

Unrealistic in most enterprise environments?

Page 34: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Microservices? More like client-server

µservice A

Single Page App in

Browser

API Gateway service

SAAS Service A

SAAS Service B

µservice B

µservice C

µservice D

µservice E

µservice F

Monolith is now in the browser

Page 35: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Do you need true "micro services"?

• There might not even be a real requirement for going from self contained systems to "true" microservices.

• You might want to keep the core parts of your business as "self contained systems" and add more functionality around these systems as smaller microservices.

• In many context, microservices architecture has started to mean this style of architecture. That's why "micro" is not a very meaningful term in this context.

• Applying Microservices is more about building "cloud-native" 12-factor applications that can be run on cloud platforms (where servers are cattle and not pets).

Page 36: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Recommendations

• Big monolithic systems cause trouble - don't let any single code base become too large. • Split your system in modules and gradually migrate

from a monolith, to vertical slices, then to self contained systems and/or microservices. Refine as you go.

• Split the database too. Don't share the database since it usually leads to a monolith.

• Build "cloud native" systems and 12-factor apps. Use Spring Cloud and Reactor that contains helpers for this way of building applications. Functional reactive programming with Reactive Streams is a way to handle complexity and reduce coupling in certain use cases. It's not only about scaling to masses.

Page 37: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

• Learn Domain Driven Design and the Bounded Context. • http://martinfowler.com/bliki/BoundedContext.html

http://www.slideshare.net/adriancockcroft/dockercon-state-of-the-art-in-microservices/43

Page 38: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Strategic design

Not all of a large system will be well designed. Some or none will be.

-Eric Evans

Page 39: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Why is Domain Driven Design important?Success developing useful models comes down to three points. 1. Sophisticated domain models are achievable and worth

the trouble. 2. They are seldom developed except through an iterative

process of refactoring, including close involvement of the domain experts with developers interested in learning about the domain.

3. They may call for sophisticated design skills to implement and to use effectively.

source: Eric Evans: Domain Driven Design

You can only achieve "bounded contexts" or "vertical slices" with proper design. Microservices are really about building in this style. See Kent Beck's blog article "To Design or Not To Design? A Third Good Question" from 2009, http://www.threeriversinstitute.org/blog/?p=338 gives good insight.

Page 40: GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

@lhotari

Q&A As a software developer, choose your battles and fight for what actually matters. -Me just know

Write software that matters. -Dan North

[email protected]