Share
Embed
Becoming Ninja of Microservices
Shubham
November 26, 2018
Transcript
36 slides
-
Have you thought how world’s biggest on demand video streaming
service works ? Or How does the food you order reaches you ? Hyderabad -
What might go wrong with Monoliths ? • Huge application
size • Managing data becomes a challenge • Assurances of Reliability - Becomes harder as you grow, you have to solve dependency graphs and have proper testing frameworks in place • Continuous Deployment & Scalability becomes harder and harder • Different Computational Requirements • Stick to one single language, framework and Database -
“Service can be an independently existing logical part of the
business domain you are working in” - Martin Fowler -
“Small Autonomous services that work together, modelled around a business
domain” - Sam Newman -
“People try to copy Netflix, but they can only copy
what they see. They copy the results not the process” - Adrian Cockcroft, Ex-Cloud Architect Netflix -
“Microservices is all about optimising for speed and scale” -
Christian Posta, Principal Architect RedHat -
Few more Services ... • Rider Management • Trip Management
and Tracking • Hotel Reservation • Subscription service -
Microservices Key Concepts • How to model data, transactions and
retrieval processes • How do different services communicate with each other • How to define services and make them discoverable for product development -
How to Model Data ? • Domain Driven Design •
Be language and framework agnostic ◦ Can be records in functional programing ◦ Can be Document in NoSQL ◦ Tuple in RDBMs • Abstraction ◦ Earth is sphere • Data Selection ◦ Want to represent spherical coordinates of earth on piece of paper • Map real world to your world - Formulaism ◦ Convert spherical coordinates to flat coordinates • Assertion ◦ Preserve direction between points -
How to model transactions? • ACID ◦ Atomicity - All
or none ◦ Consistent - A transaction cannot leave the database in an inconsistent state ◦ Isolated - No transaction interfere with each other ◦ Durable • Easy to say hard to implement in microservices • BASE ◦ Basic Availability ◦ Soft State ◦ Eventual Consistency -
“Immutable transactional history of every single state change of all
records that has happened so far” - Phillipa Avery, Tech Lead Download Services, Netflix -
Event Driven Architecture • Commands - Create, Delete, Update •
Events - Order Created, Amount Reserved, Transaction Completed, Order Confirmed, Rider Allocated …… • Event Bus or Message broker - All services push events here • Publisher of events - Each service will have one, pushes event to the event bus • Subscriber of events - Each service will have one, consumes the events from event bus • Event store - the time machine, stores the event with state - Published, Processed -
Key Concepts of Inter Process Communication One To One one
request - one service One To Many One request multiple service Synchronous Timely response from service. Client may even block when it waits Request/Response Traditional HTTP APIs - Asynchronous Client doesn’t block itself waiting for the response. And the response if any is not necessarily sent immediately Notification No reply expected Publish/subscribe A service produces a message which can be consumed by many services (PubNub) Request/async Response Async reply expected Publish/async response Async response expected by the publisher -
Problems with being Direct • Client App may have to
call multiple services to render a page. Ex: Amazon claims that 100 services are called to render a page • Handling different formats of communication with different services. Ex: One service might use GRPC, other might follow REST • Refactoring in a service might affect client app • Load balancing and throttling becomes really difficult • Less Secure -
API Gateway • Single Point authorized entry • Encapsulation fine
grained APIs of each microservice into tailor made response structure for each client • Routing request to right service • Load balancing and throttling • Caching and Reliability -
Interesting Question for Q/A - Can GraphQL works as API
Gateway ? Location