π§© Smart Library System β Microservices Architecture #
Overview #
In the microservices version of the Smart Library System, the application is divided into three independent services β each responsible for a specific domain: User, Book, and Loan. Every service has its own database and communicates with others via HTTP APIs (no queues or Kafka involved in this version).
π§± Services Overview #
1. User Service #
Handles registration, profile management, and user-related queries.
- πͺ REST Base Path:
/api/users
- π¦ Owns a user database.
πΉ API Endpoints #
POST /api/users
#
Register a new user.
{
"name": "Alice",
"email": "[email protected]",
"role": "student"
}
GET /api/users/{id}
#
Fetch user details by ID.
2. Book Service #
Manages book inventory, search, and updates to availability.
- πͺ REST Base Path:
/api/books
- π¦ Owns a book database.
πΉ API Endpoints #
POST /api/books
#
Add a new book.
{
"title": "Clean Code",
"author": "Robert C. Martin",
"isbn": "9780132350884",
"copies": 3
}
GET /api/books?search=code
#
Search books by title, author, or keyword.
PATCH /api/books/{id}
#
Update a book’s available copies (used by Loan Service during issue/return).
{
"copies": 2
}
3. Loan Service #
Issues and returns books by communicating with both User Service and Book Service.
- πͺ REST Base Path:
/api/loans
- π¦ Owns a loan database.
πΉ API Endpoints #
POST /api/loans
#
Create a loan.
{
"user_id": 1,
"book_id": 42
}
Process:
- Validate
user_id
viaUser Service
. - Validate
book_id
and availability viaBook Service
. - If all checks pass, reduce the book’s available copy count.
POST /api/returns
#
Return a borrowed book.
{
"loan_id": 1001
}
Process:
- Update loan status.
- Increment book availability in Book Service.
GET /api/loans/user/{user_id}
#
Get a user’s loan history (active and returned books).
π Inter-Service Communication #
- Loan Service makes HTTP calls to:
User Service
: to validate user identity.Book Service
: to check and update book inventory.
No shared database. Each service is data-isolated for decoupling and autonomy.
π’οΈ Databases (One per service) #
Service | Database | Tables |
---|---|---|
User Service | user_db |
users |
Book Service | book_db |
books |
Loan Service | loan_db |
loans |
βοΈ Deployment Strategy #
Each microservice:
- Runs in its own container or VM.
- Has its own codebase, tests, deployment pipeline.
- Can be updated, scaled, or restarted independently.
β Advantages of Microservices #
- Independent development and deployment.
- Fault isolation: one service failing doesnβt crash the whole app.
- Easier scaling: Book Service can be scaled independently if traffic spikes.
β οΈ Trade-offs #
- Increased operational complexity.
- Requires robust service discovery, monitoring, and API versioning.
- Debugging across services can be harder without centralized logs.