netflix oss and hateoas deployed on production - javaland
TRANSCRIPT
![Page 1: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/1.jpg)
@andreasevers
Netflix OSS and HATEOAS deployed on production
![Page 2: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/2.jpg)
@andreasevers
WHOAMI
• Work for Ordina Belgium
• Open source enthusiast
• Spring contributor
• Speaker
• Technical lead & coding architect @ Proximus
• Marathon runner
![Page 3: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/3.jpg)
@andreasevers
![Page 4: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/4.jpg)
@andreasevers
Benefits
• Small, easy to understand code base • Easy to scale • Easy to throw away • Easy to deploy • Ability to use a different technology stack • Smaller teams • System resilience
![Page 5: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/5.jpg)
@andreasevers
Pitfalls
“If you can't build a monolith, what makes you think microservices are the answer?”
Simon Brown
![Page 6: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/6.jpg)
@andreasevers
Pitfalls
• Failing to adopt a contract-first approach • Assuming the wrong communication protocol • Introducing a shared domain model • Defining inappropriate service boundaries • Neglecting DevOps and testing concerns • Disregarding the human factor • Operational complexity not under control • Failing to embrace eventual consistency
![Page 7: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/7.jpg)
@andreasevers
Netflix OSS
![Page 8: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/8.jpg)
@andreasevers
Gateway
![Page 9: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/9.jpg)
@andreasevers
Gateway – What’s the use?
![Page 10: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/10.jpg)
@andreasevers
Gateway
µS µS µS µS µS µS
![Page 11: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/11.jpg)
@andreasevers
![Page 12: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/12.jpg)
@andreasevers
![Page 13: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/13.jpg)
@andreasevers
![Page 14: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/14.jpg)
@andreasevers
“API Gateways are fast becoming the Enterprise Service Bus of the microservices era”
Sam Newman
Gateway
![Page 15: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/15.jpg)
@andreasevers
Service Registry
Service Registry
loyalty
user billing
billing’
loyalty user user origin
Origin 1
Origin 2 billing
loyalty origin
![Page 16: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/16.jpg)
@andreasevers
Service Registry
Service Registry
loyalty
user billing
billing’
loyalty user
billing user origin
Origin 1
Origin 2
loyalty origin
![Page 17: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/17.jpg)
@andreasevers
billing
Service Registry
Service Registry
loyalty
billing
billing’
loyalty user user origin
loyalty origin
Origin 1
user
billing’
billing Origin 2
![Page 18: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/18.jpg)
@andreasevers
Service Registry
Service Registry
loyalty user user origin
loyalty origin
Origin 1 billing Origin
2
Service Registry
loyalty user user origin
loyalty origin
Origin 1 billing Origin
2
loyalty
Cached Registry
![Page 19: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/19.jpg)
@andreasevers
Service Registry
![Page 20: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/20.jpg)
@andreasevers
![Page 21: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/21.jpg)
@andreasevers
![Page 22: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/22.jpg)
@andreasevers
Circuit Breaker
Backend µS
![Page 23: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/23.jpg)
@andreasevers
Circuit Breaker
Backend µS
![Page 24: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/24.jpg)
@andreasevers
Circuit Breaker
µS
stream
information
Backend
![Page 25: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/25.jpg)
@andreasevers
Circuit Breaker - Dashboard
![Page 26: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/26.jpg)
@andreasevers
Circuit Breaker - Dashboard
![Page 27: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/27.jpg)
@andreasevers
Config
µScustomer
µSuser
µSloyalty
Config Server
![Page 28: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/28.jpg)
@andreasevers
Metrics & Admin
![Page 29: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/29.jpg)
@andreasevers
Metrics & Admin
![Page 30: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/30.jpg)
@andreasevers
Metrics & Admin
![Page 31: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/31.jpg)
@andreasevers
Metrics & Admin
![Page 32: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/32.jpg)
@andreasevers
Metrics & Admin
![Page 33: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/33.jpg)
@andreasevers
Metrics & Admin
![Page 34: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/34.jpg)
@andreasevers
Metrics & Admin
![Page 35: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/35.jpg)
@andreasevers
Metrics & Admin
![Page 36: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/36.jpg)
@andreasevers
Contracts & loose coupling We can achieve this by using Hypermedia
![Page 37: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/37.jpg)
@andreasevers
Hypermedia
Hypermedia As The Engine Of Application State
![Page 38: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/38.jpg)
@andreasevers
Hypermedia
h8ps://vimeo.com/20781278
Sub-constraints:• IdenDficaDonofresources(URIs)• ManipulaDonviarepresentaDons(request&
responsebodies)
• Self-descripDvemessages(headers)• HypermediaastheengineofapplicaDon
state
HTTPasapplica+onprotocol
![Page 39: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/39.jpg)
@andreasevers
Hypermedia
h8ps://vimeo.com/20781278
Sub-constraints:• IdenDficaDonofresources(URIs)• ManipulaDonviarepresentaDons(request&
responsebodies)
• Self-descripDvemessages(headers)• HypermediaastheengineofapplicaDon
state
Ifyoudon’tdothis
Thenyoudon’tadheretothis Andyouaremissingout
onthese
![Page 40: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/40.jpg)
@andreasevers
Concretely?
![Page 41: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/41.jpg)
@andreasevers
Hateoas In Action
![Page 42: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/42.jpg)
@andreasevers
![Page 43: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/43.jpg)
@andreasevers
![Page 44: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/44.jpg)
@andreasevers
![Page 45: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/45.jpg)
@andreasevers
![Page 46: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/46.jpg)
@andreasevers
![Page 47: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/47.jpg)
@andreasevers
Hateoas in action
How would you explain to a client to get to the Nerd in the Basement painting? A. Go to Amazon.com, in the categories go to fine arts, follow
paintings, more specifically oil paintings, and click on the one with the title Nerd in the Basement
B. Type http://www.amazon.com/Nerd-in-the-Basement/dp/B00L849CSS/ref=lp_6685279011_1_2?s=art&ie=UTF8&qid=1431864368&sr=1-2 in your browser
![Page 48: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/48.jpg)
@andreasevers
Hateoas in action
HTML is a hypermedia format <a> is a link with method GET <form> is a link with method POST (or other if specified)
The browser understands this syntax and shows a link or a form if the server response contains these tags
![Page 49: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/49.jpg)
@andreasevers
Hateoas Requirements
Communication between Client and Server depends on:
• Where does the client have to start? • Root API • In regular websites: the homepage
• Where am I? • How do I interpret the current API response? • In regular websites: the syntax of HTML is interpreted by the browser
• Where can I go? • What does a link or form with a certain relation or class mean? • In regular websites: link with relation “stylesheet”, form with action “login”
![Page 50: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/50.jpg)
@andreasevers
Hateoas in action
Amazon.com (and any other website in the whole world wide web) applies Hateoas. Why wouldn’t your API do the same?
![Page 51: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/51.jpg)
@andreasevers
Hateoas Benefit: Runtime action discovery
GET /account/12345 HTTP/1.1 HTTP/1.1 200 OK <?xml version="1.0"?> <account>
<account_number>12345</account_number> <balance currency="usd">100.00</balance> <link rel="deposit" href="/account/12345/deposit" /> <link rel="withdraw" href="/account/12345/withdraw" /> <link rel="transfer" href="/account/12345/transfer" /> <link rel="close" href="/account/12345/close" />
</account>
![Page 52: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/52.jpg)
@andreasevers
Hateoas Benefit: Runtime operation discovery
GET /account/12345 HTTP/1.1 HTTP/1.1 200 OK <?xml version="1.0"?> <account>
<account_number>12345</account_number> <balance currency="usd">-25.00</balance> <link rel="deposit" href="/account/12345/
deposit" /> </account>
![Page 53: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/53.jpg)
@andreasevers
Hateoas Concern: Scope
In case of one or two clients built in the same team, it is arguable whether auto-discoverability is really a necessity
![Page 54: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/54.jpg)
@andreasevers
Hateoas Benefit: Non-structural Changes
“categories/1/oil-paintings/1234” auto-discoverable through HATEOAS as “categories[1].oil-paintings[1234]” will not break when 1234 as id is changed to “basementNerd”
![Page 55: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/55.jpg)
@andreasevers
Hateoas Benefit: Changing the URI of a resource “categories/1/oil-paitings/1234” being returned as part as the response body of “categories/1” will not break the client
![Page 56: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/56.jpg)
@andreasevers
Content Types
• JSON • NOT hypermedia-aware by default • Needs a fixed format to support links and forms • Many formats available
• XHTML • IS hypermedia-aware by default • Harder to process XHTML responses using javascript (xpath is required) • The API responses can also be read by a human as regular HTML pages
• SVG, Atom, HTML • Similar as XHTML but not preferred
![Page 57: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/57.jpg)
@andreasevers
JSON Formats • JSON-LD
• Augmenting existing APIs without introducing breaking changes • Needs HYDRA as a vocabulary for communicating operations • Decoupling of API serialization format & communication format
• HAL • Minimal, light weight syntax and semantics • Offers most of the benefits of using a hypermedia type • Easy to convert existing API to HATEOAS • Chosen and supported by Spring • No support for specifying operations
• Collection+JSON • Can list queries that your collection supports and templates that clients can use to alter your collection • Great for publishing user editable data
• SIREN • Represents generic classes of items • Supports operations • Concept of classes, bringing a sense of type information to your API responses
![Page 58: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/58.jpg)
@andreasevers
Considerations
Maturity
Client implementation
Caching
Versioning
![Page 59: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/59.jpg)
@andreaseversh8ps://speakerdeck.com/ankinson/documenDng-resTul-apis-webinar
![Page 60: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/60.jpg)
@andreasevers
What should you document
Resources
Links
Cross-cutting concerns
![Page 61: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/61.jpg)
@andreasevers
What shouldn’t you document
URIs
![Page 62: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/62.jpg)
@andreasevers
What does it look like when you get it wrong?
![Page 63: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/63.jpg)
@andreasevers
What does it look like when you get it right?
![Page 64: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/64.jpg)
@andreasevers
Swagger
Doesn’t support Hypermedia
![Page 65: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/65.jpg)
@andreasevers
Swagger
It’s URI centric
![Page 66: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/66.jpg)
@andreasevers
Swagger
It’s leaky
![Page 67: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/67.jpg)
@andreasevers
Swagger
It’s huge
![Page 68: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/68.jpg)
@andreasevers
Best practices for documentation
Write as much as possible in a format which is designed for writing Don’t use the implementation to provide the documentation Provide some guarantees that the documentation is accurate
h8ps://github.com/spring-projects/spring-restdocs
![Page 69: Netflix OSS and HATEOAS deployed on production - JavaLand](https://reader030.vdocuments.us/reader030/viewer/2022020314/5884a57e1a28ab76798b4add/html5/thumbnails/69.jpg)
@andreasevers
Thank you for your attention
@andreasevers
https://github.com/oraj-360 http://registry.oraj360.cfapps.io/ https://netflix.github.io/ http://projects.spring.io/spring-cloud/ http://projects.spring.io/spring-hateoas/ https://github.com/spring-projects/spring-restdocs