The Cloud-Natives are RESTless
Is REST the BEST?
@frankgreco
Background
§ Chairman NYJavaSIG (javasig.com) § Largest Java UG in NA 8k+ members § First Java UG ever! Sept 1995
§ mail: [email protected] § twitter: @frankgreco § yell: “Hey Frank!”
REST has served us well for the past 15 years as a
style of cross-language, synchronous distributed
computing that is web-friendly.
Where does it fit in a Cloud-centric world?
What are the alternatives to REST for event-based
Java microservices?
What reactive frameworks should Java developers
learn and use in their services and overall application
architecture?
Goal
Kenny Bastani Developer Advocate Pivotal
Konrad Malawski Senior Developer Lightbend
Todd Montgomery Senior Consultant StonTor
Panelists
StonTor
Thank You!
@frankgreco
The cloud-natives are RESTlessKenny Bastani Spring Developer Advocate
Kenny Bastani
@kennybastani
Spring Developer Advocate
Microservices
Distributed applications change the way we communicate
We started with the monolith…
Cultural problems with monoliths
• Slows our velocity getting into production
• It takes too long to ramp up new engineers
• The code base is just too large for anyone one person to fully comprehend
• Centralized authority and change management slows progress (DBA, Ops)
Operational problems with monoliths
• Coordinated releases batch many changes together from different teams
• Operations drives the runtime environment of applications
• Operators take on all operational responsibility (including VM upgrades)
• Deploy everything at once or nothing at all
We then moved towards SOA…
@kennybastani
We have now arrived at microservices…• Each team gets one database and one service
• Centralized resources are provided as backing services that are shared for data consistency, caching
Cloud native applications
@kennybastani
Distributed Applications• Each microservice needs to communicate outside containers
• Service discovery provides an automatic method for finding other service dependencies
Event Sourcing• Aggregates can be used to generate the consistent state of any object
• It provides an audit trail that can be replayed to generate the state of an object from any point in time
• It provides the many inputs necessary for analyzing data using event stream processing
• It enables the use of compensating transactions to rollback events leading to an inconsistent application state
• It also avoids complex synchronization between microservices, paving the way for asynchronous non-blocking operations between microservices
Transaction logs
Event logs are transaction logs•Use event sourcing in your microservices to ensure
consistency of your distributed system
•Don’t store state with microservices, store events •Use event stream analysis to observe the active usage of
your cloud native application in real-time
The Cloud-Natives are RESTless
Build powerful concurrent & distributed applications more easily.
Akka is a toolkit and runtime for building highly concurrent, distributed, and resilient message-driven applications on the JVM
Build powerful concurrent & distributed applications more easily.
Akka is a toolkit and runtime for building highly concurrent, distributed, and resilient message-driven applications on the JVM
”The actor model in computer science is a mathematical model of concurrent computation that treats actors as the universal primitives of concurrent computation. ”
Wikipedia
The Actor Model
An Actor
and acts on them by: • Sending messages • Changing its state / behaviour • Creating more actors
receives messages
An Actoran addressable, location-transparent, entity
Show diagram showing people interacting with each other.
Not Only Server-Client
Todd mentioned HTTP/2 “Server Push”, but it still needs the first request to be made from the Client.
HTTP is inherently request/response, HTTP/2 just adds a few features.
TODO: Show diagram example that we can notify anyone in the cluster. TODO: Show how costly it would be to do the same with REST - everyone has to become a server and talk to each other via clients.
Resources with identifiers, actual-“push”HTTP/2 “Server Push”… still needs an initial “pull”.
Resources with identifiers, actual-“push”HTTP/2 “Server Push”… still needs an initial “pull”.
https://blog.cloudflare.com/announcing-support-for-http-2-server-push-2
Resources with identifiers, actual-“push”HTTP/2 “Server Push”… still needs an initial “pull”.
Not Only JSON
“The Internet is running in debug mode.” — Rüdiger Möller
http://java-is-the-new-c.blogspot.de/2014/10/why-protocols-are-messy-concept.html
Not Only JSON“The Internet is running in debug mode.”
— Rüdiger Möller
Actually solving real problems we saw in the field.
Reactive Streams
Reactive Streams – why it all startedWe literally had customers kill legacy services they had to integrate with by just using Akka “the normal way”.
Needed to introduce asynchronous, application-level flow control.
Reactive Streams made it trivial for end user, it’s a no brainer now - it just works.
TODO diagram with servers burning / being overloaded. And show OOMs on sending side.
Defaults to Async Messaging
Clustered Actors, any-to-any communication
TODO diagram about communicating “right back to the original sender”
TODO show diagram how expensive this would be with in “how people usually do REST”, and how it could be done, but rarely people do.
Clustered Actors, simple failure model
TODO diagram that shows that everything is basically message loss. There is no “funky state” in the communication channel.
Node failure = message loss. Not responsive = message loss. etc.
More tools in the toolbox
Akka Clusterand cluster tools
Akka Clusterand cluster tools
Akka Streamsasync & back-pressured
More tools in the toolbox
Read more:Reactive Streams spec: reactive-streams.org Akka documentation: akka.io/docs
Get involved: sources: github.com/akka/akka (see also “community” tag) mailing list: https://groups.google.com/forum/#!forum/akka-user gitter channel: https://gitter.im/akka/akka
Contact: Konrad [email protected] Malawski http://kto.so
The Cloud-Natives are RESTless
Todd L. Montgomery@toddlmontgomery
StoneTor
WebSocketReactive APIs
HTTP/2Microservices
Changes in a post-REST World
Where we have come from…
@toddlmontgomery
Request
Response
HTTP 1.1RFC 2068, 2616, …, 7230-7240
SynchronousRequest/Response
Bi-Directional… kinda,but…
Event
Event
… onlyone direction
at-a-time
June 2014
✓ ASCII Encoded✓ Very Synchronous✓ Many TCP Connections✓ Request / Response Focus
Request-Response is not enough
It’s never been enough!
“Everything changes and nothing stands still”
— Heraclitus of Ephesus
✓ What about data feeds?✓ What about interactivity?✓ What about …
Changing Needs
WebSocket
@toddlmontgomery
AsyncRequest/
Response
Streaming
WebSocketRFC 6455
Full Duplex, Asynchronous“TCP over the Web”
EventsEvents
101 Switch
HTTP Upgrade
Ingest
https://tools.ietf.org/html/rfc6455
Really aTransportProtocol
Reactive APIs
The Lure of Complexity
The Need for Simplicity
Asynchronous is the norm
Today
Composition is hard
ReactiveX
http://reactivex.io/
Observables
✓ Non-Blocking Back Pressure✓ Heterogeneous Connectivity
Challenges
Dealing with Back Pressure
✓ ReactiveStreams✓ RxJava 2.0✓ Akka Streams✓ java.util.concurrent.Flow (JEP 266)
http://www.reactive-streams.org/
But, language constructs are notthe main story
Your API is a protocol
Treat it like one
Rx Heterogenous Connectivity
✓ ReactiveSocket
http://reactivesocket.io/
HTTP/2
HTTP
There is emerging implementation experience and interest in a protocol thatretains the semantics of HTTP without the legacy of HTTP/1.x messageframing and syntax, which have been identified as hampering performance andencouraging misuse of the underlying transport.
— IETF httpbis Charterhttp://datatracker.ietf.org/wg/httpbis/charter/
@toddlmontgomery
AsyncRequest
AsyncResponse
SPDY & HTTP/2RFC 7540
Async Request/ResponseStreaming (Server Push)
EventsEvents
https://tools.ietf.org/html/rfc7540
✓ Persistent Connection✓ Binary Encoding ✓ Multiple Streams✓ Efficient Headers (HPACK)✓ Server Push
✓ Framing✓ Streams✓ Settings
HTTP/2 & APIs
For APIs,
HTTP/2 = Interesting Times Ahead
Microservices
Stuff that dreams are made of…
✓ Service Independence✓ Fast Service Evolution✓ Service Isolation✓ Independent Deployability
Moving Faster
@toddlmontgomery
• http://ietf.org/• http://www.reactive-streams.org/• http://reactivesocket.io/• GitHub @tmontgomery• Twitter @toddlmontgomery
Thank You!