Part-1: High level interview question
Created on: Sep 27, 2024
-
The number of users on irctc is in millions and on amazon, it is roughly 310 million. When we sign in, it takes only a fraction of seconds. Could you please provide thoughts on internal working that make this possible.
- User data is stored in distributed databases, where data is partitioned (sharding) and replicated across multiple machines. For example data can stored in casandra which is one of best option for heavy read and write.
- Load balancing ensure that no single broswer is overwhelmed by user request.
- Caching: User session or token can be cached in redis or memcache db for fast retrieval.
- Use of session toekn for authentication for authentication and authorisation after user sign in.
- Platforms like Amazon and IRCTC use horizontal scaling to add more servers as traffic increases.
-
How can we efficiently handle multiple concurrent requests in a ticket booking system to ensure data consistency, prevent race conditions, and optimize performance?
-
What are the rest principle ?
- Uniform Interface: Restful api should have consistent and standardized interface. Below is not following uniform interface principle.
GET /product/getAllProducts GET /products/id/123 POST /add_new_product DELETE /delete_product?id=123 PUT /update_product?productId=123- Client-Server: Client and serer has a Separation of concerns. The client handles the user interface and user experience, while the server manages the data and business logic.
Below is a example which does not follow this principle.
POST /tasks?userAppVersion=3.2&clientDeviceType=Mobile { "title": "Complete project documentation", "description": "Finish the remaining sections", "dueDate": "2024-10-20" }{ "status": "success", "task": { "id": 123, "title": "Complete project documentation", "description": "Finish the remaining sections", "dueDate": "2024-10-20" }, "clientViewConfig": { "displayColor": "#0000FF", // Response includes client-specific UI info "fontSize": "16px", // UI information directly provided by the server "layout": "compact" // Layout dependent on client version and device type } }- Statelessness: Each request from the client to the server must contain all the information the server needs to fulfill the request.
4.Cacheability: This principle states that response should implicitly or explicitly label itself as cacheable or non-cacheable.
- Layered System: In distributed system there are multiple microservice which expose their api. All these api should not be exposed to client. There can be a single API gateway with load balancer which will handle the request.
-
What is api versioning and how we can achieve it. Creating different versions of an API ensures compatibility between old and new clients when changes are made to the API. Below are the main ways we can achieve this.
-
URI Path Versioning: (most common)
GET /api/v1/products GET /api/v2/products -
Query Parameter Versioning
GET /api/products?version=1 GET /api/products?version=2- Header-Based Versioning
GET /api/products Header: "API-Version: 1" -
-
Explain about authentication and authorization in microservices.
-
What are non functional requirement
- fault-tolerant:
-
What is bounded context design pattern ?
-
What is difference between canery and blue green deployment ?
-
What are the demerit of monolithic application that microservice pattern solves ?
