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

Welcome To Era of Microservices

Shubham
November 06, 2017

Welcome To Era of Microservices

A short story on how to make fantastic Microservice Architecture like that of Netflix and Zomato. I have tried to cover the following topics briefly
What are monoliths?
Deep Dive Into Microservice Architecture
Introduction To API Gateway
Introduction To Inter-Service Communication
Introduction To Event Driven Data Management
Monoliths vs Microservices

Shubham

November 06, 2017
Tweet

More Decks by Shubham

Other Decks in Technology

Transcript

  1. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API What are Monoliths? Deep Dive Into Micro Service Architecture Introduction API Gateway Introduction To Inter Service Communication Introduction To Event Driven Data Management Monoliths vs Micro Services What We Will Try To Cover ?
  2. Restaurant Management Order Management User Management Billing Payment Notification Let’s

    Meet Monster of The Hour - Monolith Payments adapter Database adapter Notifications Adapter Web API Mobile API
  3. Restaurant Management Order Management User Management Billing Payment Notification Payments

    adapter Database adapter Notifications Adapter Web API Mobile API Everything Seems Right! What’s the Problem Then?
  4. Restaurant Management Order Management User Management Billing Payment Notification Payments

    adapter Database adapter Notifications Adapter Web API Mobile API Huge application size Reliability cannot be insured Continuous Deployment & Scalability Different Computational Requirements Stick to one single language, framework and Database Restaurant Management Order Management User Management Billing The Monolithic Hell Review & Recommendation
  5. Restaurant Management Order Management User Management Billing Payment Notification Payments

    adapter Database adapter Notifications Adapter Web API Mobile API Let’s Beat The Monster Warriors
  6. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API What Exactly is a Micro Service ?
  7. “Small Autonomous services that work together, modelled around a business

    domain” - Sam Newman “Service can be an independently existing logical part of the business domain you are working in” - Martin Fowler Definition of a Micro-service “If you further normalise service oriented architecture you get micro services architecture” - Shubham Pachori
  8. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API Deep Dive Into Micro Service Architecture
  9. Restaurant Management Order Management User Management Billing Payment Notification Payments

    adapter Database adapter Notifications Adapter Web API Mobile API Alright But How is it better than Monolith?
  10. Restaurant Management Order Management User Management Billing Payment Notification Payments

    adapter Database adapter Notifications Adapter Web API Mobile API The Cube of Scalability
  11. Restaurant Management Order Management User Management Billing Payment Notification Payments

    adapter Database adapter Notifications Adapter Web API Mobile API Cube of Scalability Then - X Axis Docker Docker Docker EC2 Instance EC2 Instance
  12. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API Cube of Scalability Now - X axis Docker Docker Docker Docker EC2 Instance EC2 Instance
  13. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API Cube of Scalability Now - Y axis User Management Order Management Billing Review Recommendation Database adapter Database adapter Database adapter Database adapter
  14. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API Cube of Scalability Then & Now - Z axis Database adapter User Management Database adapter
  15. Restaurant Management Order Management User Management Billing Payment Notification Payments

    adapter Database adapter Notifications Adapter Web API Mobile API Let’s Switch On Our App
  16. Restaurant Management Order Management User Management Billing Payment Notification Payments

    adapter Database adapter Notifications Adapter Web API Mobile API Let’s Switch On Our App • Restaurant Listing • Restaurant Menu Listing • Account Information • Order History • Order Tracking • Order Support • Review and recommendations
  17. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API Order Management How will your App Interact With Multiple Services? User Management Menu Listing Review Recommendation Restaurant Management API API API API API
  18. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API What’s the problem in Client - Micro service Direct Interaction? API User Management • Mismatch in the requirement of client and fine grained APIs of micro services. Amazon claims that to render one page they are calling 100s of services. • Some micro service might not use web friendly protocols to communicate with them • Refactoring of a service in future becomes difficult
  19. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API Order Management A Better Approach - API Gateway User Management Menu Listing Review Recommendation Restaurant Management API API API API API API Gateway
  20. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API A Better Approach - API Gateway API Gateway • An API Gateway encapsulates the internal system architecture and combines all the fine grained APIs of micro-services into a coarse grained API that is tailored for each client • Act as a single entry point into the system • It is responsible for request routing, composition and protocol translation (all micro services may not be on HTTP protocol). • All requests first go to API Gateway. It then routes requests to the appropriate micro- service. • Quite often to handle a request of client API Gateway will invoke multiple micro services and aggregate the results and serve it to client. • It can handle additional responsibilities viz. authentication, monitoring, load balancing and caching
  21. Restaurant Management Order Management User Management Billing Payment Notification API

    API API API API API How Do Service Communicate To Each Other?
  22. Restaurant Management Order Management User Management Billing Payment Notification API

    API API API API API Inter Service 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
  23. Order Management User Management Billing Payment Notification 1. Checks out

    Notification 2. Get User Info Request/Response 3. Get User’s Payment info Request/Response 4. Payment Successful Pub/Sub 5. Order Created Pub/Sub 7. Accept Order Request/Response 8. Order Accepted Notification 9. Order Accepted Pub/Sub Restaurant 6. New Order Notification Restaurant Management
  24. Database adapter User Management Order Management Database adapter Database adapter

    How to manage Data & its consistency across all services?
  25. Database adapter With Monolith Everything Was Simple • With one

    transactional RDBMS all transactions were ACID(Atomic, Consistent , Isolated, Durable) • As there was only one database A.Querying multiple tables of separate module was easy B.Carrying out transaction which require table updates of multiple modules was easy
  26. With Micro services - It’s a Bit Complicated • Each

    micro service maintains its own database which is not supposed to be same RDBMS. It can be a NoSQL store • Each micro service can only access and manipulates its own database directly. • Challenge 1: How to implement business transaction that maintain consistency across multiple services? • Challenge 2: How to implement queries that retrieve data from multiple services? User Management Database adapter Database adapter Order Management
  27. Event Driven Architecture - Solving Challenge 1 User Management Order

    Management Message Broker Order Created Event id customer_id status Total 900 891 New 980 Place Order User Store [ { user_id: 891 wallet_amount: 1000 }, ] Reserved Amount Store [ { user_id: 891, order_id: 900, debit_amount: 980 }, ]
  28. Event Driven Architecture - Solving Challenge 1 User Management Order

    Management Message Broker Order Created Event id customer_id status Total 900 891 New 980 Place Order Order Created Event User Store [ { user_id: 891 wallet_amount: 1000 }, ] Reserved Amount Store [ { user_id: 891, order_id: 900, debit_amount: 980 }, ] Amount Reserved Event
  29. Event Driven Architecture - Solving Challenge 1 User Management Order

    Management Message Broker Order Created Event id customer_id status Total 900 891 Open 980 Place Order Order Created Event User Store [ { user_id: 891 wallet_amount: 1000 }, ] Reserved Amount Store [ { user_id: 891, order_id: 900, debit_amount: 980 }, ] Amount Reserved Event Amount Reserved Event
  30. Event Driven Architecture - Solving Challenge 2 User Management Order

    Management Message Broker Order Created Event Order Confirmed Event Order On-Way Event Order Delivered Event Customer Created Event Materialised View
  31. Monolith Microservice • Simplicity • One shot deployment • Availability

    tricky, consistency yes (Remember CAP Theorem) • Inter module refactoring simple • Its cool, Its sexy. But async and distributed computing makes it complicated • Partial Deployment • Availability - Recommendation service goes down, shopping cart works. Nothing stops shopping • One micro service refactors it triggers an avalanche of refactoring as most of the times module boundaries were not defined correctly • Preserves modularity • Multiple Platforms
  32. Restaurant Management Order Management User Management Billing Payment Notification API

    Gateway API API API API API API Shubham Pachori @spachori94