Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gr8Conf: Implementing loosely coupled microservices with Grails

Gr8Conf: Implementing loosely coupled microservices with Grails

Grails 3 is s a great starting point for creating microservices and many projects are following this path. However many microservice landscapes are still based on synchronous calls to REST Resources which obviously increases coupling between those applications. This talk focusses on building loosely coupled microservices that are based on Domain Events, which are becoming more and more popular in the Domain Driven Design community. We will take a look at how Grails 3 helps us in building such systems by introducing the Grails 3 event system and by taking a look how we can leverage Domain Events for a decoupled communication between Grails applications.

Michael Plöd

June 01, 2017
Tweet

More Decks by Michael Plöd

Other Decks in Programming

Transcript

  1. Loosely Coupled
    Microservices with Grails
    Michael Plöd
    @bitboss

    View Slide

  2. Interactions between Microserivces
    Grails App
    A
    Grails App
    B
    Typically RESTful HTTP

    View Slide

  3. Interactions between Microserivces
    Grails App
    A
    Grails App
    B
    Grails App
    C
    Grails Ap
    D
    Grails App
    E
    Grails App
    F

    View Slide

  4. Interactions between Microserivces
    Grails App
    A
    Grails App
    B
    Grails App
    C
    Grails Ap
    D
    Grails App
    E
    Grails App
    F
    !
    "
    #
    $
    %

    View Slide

  5. Welcome to the
    Dark Side

    View Slide

  6. Challenges
    !
    "
    #
    $
    %
    Service Discovery
    Timeouts
    Errors
    Latency
    Load Balancing
    &Stability

    View Slide

  7. Usual Architecture Patterns
    > Event-Driven Architecture
    > REST
    > SOA
    > Microservices / Self-Contained Systems
    > CQRS
    > Reactive / Actor Model

    View Slide

  8. Domain Events
    > Applications can issue Domain Events
    > Domain Events are important occurrences in an Domain
    > UserVerified
    > ShoppingCartCheckedOut
    > ShipmentDelivered
    > Domain Events are usually based on eventual consistency
    > Major driver for high degree of decoupling between
    Microservices

    View Slide

  9. Domain Events
    Customer

    Notification

    Application
    Shipping

    Application
    Shipment

    Delivered

    Event
    Messaging

    System
    Shipment

    Delivered

    Event

    View Slide

  10. An event is something 

    that happened in the past
    t
    now
    Event
    Event
    Event
    Event
    Event

    View Slide

  11. ShipmentDeliveredEvent

    CustomerVerifiedEvent
    CartCheckedOutEvent
    CreateCustomerEvent

    WillSaveItemEvent

    DoStuffEvent

    View Slide

  12. An Event is always immutable
    !

    View Slide

  13. Loan Details
    Entered
    Financial
    Situation
    Entered
    Personal
    Infromation
    Entered
    Application
    Submitted
    Credit

    Application
    Scoring


    View Slide

  14. Let’s reuse the ESB
    from the failed SOA
    project

    View Slide

  15. NO

    View Slide

  16. NO

    View Slide

  17. NO

    View Slide

  18. Talking about Grails

    View Slide

  19. Loan Details
    Entered
    Financial
    Situation
    Entered
    Personal
    Infromation
    Entered
    Application
    Submitted
    Use the 

    Grails 3 

    Event System
    for handling of
    internal Events
    Use 

    RabbitMQ 

    or 

    Kafka 

    for handling of
    external Events

    View Slide

  20. Options for Events
    Event with complete
    payload
    Event with a REST URL
    Empty Event as a Feed
    update notification
    > The Event contains all relevant data
    > Enables complete async processing
    > Payload is big and can fill up your message broker
    > The Event only contains a URL to a REST-Resource and some minimal
    data, that is usually always needed
    > Small payload that is fast to transport
    > Standard cases work completely asynchronous, more complex cases
    might require a synchronous roundtrip (without service lookup though)
    > The Event has no payload at all, it is just a notification
    > The payload, be it data or a REST URL, is usually contained in an
    Atom Feed
    > Event is a polling trigger for the feed

    View Slide

  21. https://github.com/mploed/event-driven-spring-boot
    Let’s replace the Scoring one
    with a Grails 3 Microservice!
    https://github.com/mploed/event-driven-grails

    View Slide

  22. THANK YOU
    I’ll post links to slides and code on Twitter

    Michael Plöd - innoQ
    @bitboss

    View Slide