23/180: Case Study — Microservices Design
I have taken a course on udemy for microservices architecture and I am going to describe the case study given over there. We will go through the main steps of architecture process:
- Functional Requirements
- Non Functional Requirements
- Mapping the components
- Define communication pattern
We are going to discuss Library Management Case study today
Library Management
- Manages books inventory
- Manages books borrowing
- Manages Customer
- Display Notifications
- Charge Annual Fee
Requirements can be divided into two parts
Functional requirements:
What the system should do?
- Web based
- Manage books inventory
- Manages customers
- Manages book borrowing
- Display Notification
- Charge Annual Fee
Non Functional Requirements:
What the system should deal with?
- How many expected concurrent users — 10
- How many books will be managed-10000
- How many borrowing in a day — 500
- What’s the desired SLA — 9/5, i.e. 9hrs 5 days
Data Volume
1 book record = 1kb
10000 books = 10 MB
1 borrowing record = 500 bytes
500 borrowing/day
182k borrowing/year -> 91 MB/year
Mapping the Components
Microservices -> Organized around business capabilities. We have well defined entities, so lets try and design the service around them.
Business Entities: Books, Borrowing, Customers
Utilites: Notifications, Payments, View
Book Service
Used to manage books inventory in the library.
- Used by libraries
- Has a database storage
- Should be synchronous (immediate response)
- Does not depend on other services.
APIs ->
- Get Books Details. GET /api/v1/book/{bookId}
- Add new book POST /api/v1/book
- Update Book PUT /api/v1/book/{bookId}
- Remove Book DELETE /api/v1/book/{bookId}
Borrowing Service
- Add a borrowing. POST /api/v1/borrowing
- Add a return POST /api/v1/borrowing
- Get Borrowing by customer GET /api/v1/borrowing/{customerId}
Customer Service
- Manage Library customers
- Used by librarians
- Has a storage
- Should be synchronous
- Doesn't depend on other service (Although refers to books and borrowings)
Notification Service
- Used to send notifications to the library customers
- Books was returned, new books added etc
- Used by other services
- Asynchronous
- Might experience load (send notifications to all users)
- We will use queue
- No immediate response required
- Distributed load
Payment Service
- Used to send payment instructions to external service
- Used by other services (for example customer joins the library)
- Asynchronous
- High Reliability is must
- We will use queue
- No immediate response required
- High availability
View Service
Used to serve static content to the web browser. HTML/CSS/JS. No API required, work directly with the browser.