# Review APP High level system design ### Content index - [Definitions and requirements of business](./RequirementsOfBusiness.md) - [Requirements of the system](#requirements-of-the-system) - [Definitions and Acronyms](#definitions-and-acronyms) - [Overview](#overview) - [Scope](#scope) - [Uses cases](#uses-cases) - [Out of Scope (Not supported)](#out-of-scope-not-supported) - [Architecture](#architecture) - [Data model](#data-model) - [Limitations & Unknowns](#limitations--unknowns) - [Data structures](#data-structures) - [Costs](#costs) ### Requirements of the system Just design the system of backend, not the frontend **Review reader** - Just get content of reviews **GET** - ***Thousand of users(1000+ readers)*** can see the reviews - They must be able to see the reviews around the world - Response time must be less than **10 seconds** - In case, the reviews is more than **100** reviews, the response should be paginated - What's going on if the server is down? (Cache, CDN, etc) **Review publisher** - Create, edit and remove reviews of cameras (**POST**, **PUT**, **DELETE**) - **10 Users** can create reviews - Service must be available 24/7 - Review publisher must be able to authenticate (**Login** and **Logout**, **JWT**, **Register**) - Review publisher must be able to upload images - Response time must be less than **300 seconds** - **10 and 20 reviews** per day (No needs a lot of resources) - Publishers just can create reviews in **America Sur** ### Definitions and Acronyms - API: application program interface - Readers: Users that just read the reviews - Publishers: Users that create, edit and remove reviews - API Management Azure: Azure API Management is a service that you can use to publish, secure, transform, maintain, and monitor APIs. - Azure Load Balancer: Azure Load Balancer delivers high availability and network performance to your applications. - Azuer App Service: Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends. - Azure Functions: Azure Functions is a serverless compute service that enables you to run code on-demand without having to explicitly provision or manage infrastructure. - Azure Database for MySQL: Azure Database for MySQL is a relational database service based on the open-source MySQL Server engine. - Azure Cache for redis: Azure Cache for Redis is a fully managed, open-source compatible in-memory data store that powers fast, high-performing applications. - Azure Container APPs: Azure Container Apps is a fully managed service that allows you to deploy and run containerized apps without having to manage servers or clusters. ### Overview The CamereReviews company needs a system to allow that photografers proffesionals upload and publish reviews of cameras for anywhere can research and purcharse the review through the portal. The company has a team of developers specialized in frontend that will develop a portal to allow that editors upload the reviews and the users can see them, and they have requested that you as a backend specialist, provide a system, including **API** that allow to do the following: - Upload reviews of cameras - Get the content of reviews to show them in the portal view in web and mobile versions - Handle of users for editors (not include visitors) - It's planned to distribute mostly in **America Sur** where is the biggest market, but also has sales in **North America**, **Europe** and very few in **Asia**. ### Scope #### Uses cases - As a **publisher** I want to login and logout in the system - As a **publisher** I want to recover my password if I forgot it - As a **publisher** I want to create and upload a review of a camera - As a **publisher** I want to edit reviews of a camera after I published it - As a **publisher** I want to delete reviews of a camera after I published it - As a **publisher** admin I want to create, edit and remove users - As a **publisher** admin I want to create, edit and remove roles (Publisher and Publisher admin) - As a **publisher** I want to publish my reviews in less than 300 seconds - As a **reader** I want to se reviews of a camera in less than 10 seconds - As a **reader** I want to read reviews of a camera - As a **reader** I don't need to login to read reviews - As a **reader** I want to filter through categories of cameras #### Out of Scope (Not supported) - No needs to support users(**readers**) to create reviews - **Review publisher** - Not support users(**publishers**) to create reviews in another continent = **Review publisher** - As a **publisher** I'd like to get analytics of my reviews - As a **publisher** admin I want to have more roles than just Publisher and Publisher admin - As a **publisher** I'd like to give feedback to reviews - As a **reader** I'd like to register, login and logout - As a **reader** I'd like to recover my password if I forgot it - As a **reader** I'd like to save reviews as favorites - As a **reader** and **publisher** I'd like to see the reviews in my language - As a **reader** and **publisher** I'd like to comment reviews ### Architecture Architecture willd developed in multiples phases. The first step will be developed the archicture without mention any tecnologie DevOps. **Phase 1 Description General without Technologies** Review app will have a API gateway(management) as a main service to handle access, auth and the unique endpoint amound services ReviewReader and ReviewPublisher will implement a database MySQL to make queries as fast as it can, actually it will be cache and database, otherwise it will have a service to authenticate users and their own database and cache too. Also we have to talk about ReviewReader, it will get more complexity to improve performance and scability for the future. This service will be handle by a load balancer to distribute the traffic and a Horizontal scaling or Horizontal container to improve performance and scability. How you can looks in the diagram below. **Architecture Diagram** ![Phase 1](https://github.com/SebasttianDaza/ReviewApp/assets/81209181/2e7a60d8-acc3-41b3-872a-b37cc8e1264d) Something really important is other service that architecture will have, it'll be a service to migrate data from database MySQL (ReviewPublisher) to database NoSQL (Review Reader). **Phase 2 Description Specific without Technologies** - API Gateway: It'll be a service intermediary between the client and the server (**ReviewPublisher** and Load Balancer (**ReviewReader**)), this will handle all request HTTP. - Load balancer: It'll handle incomin traffic accross services just for ReviewReader. - ReviewPublisher: It'll be a service that allows publishers to create, edit and remove reviews of cameras. - Auth: It'll work as a service to authenticate users and it'll be used just by ReviewPublisher. - Cache - Database - Service of Migration: It'll migrate data from NoSQL Database (**ReviewPublisher**) to SQL Database (**ReviewReader**). - Review Reader: It'll be a service that allows readers to get content of reviews of cameras. - Cache - Database **Phase 3 Description with technologies DevOps** **Architecture Diagram** ![Phase 2](https://github.com/SebasttianDaza/ReviewApp/assets/81209181/b4ce8861-266c-420a-a734-12fb84e28405) - [API Management Azure](ttps://azure.microsoft.com/en-us/products/api-management/) **API Gateway** [To learn more](ttps://learn.microsoft.com/en-us/azure/api-management/self-hosted-gateway-overview). - [Azure Load Balancer](https://learn.microsoft.com/en-us/azure/load-balancer/load-balancer-overview) **Load Balancer** - [Azure APP Service](https://azure.microsoft.com/en-us/products/app-service) **ReviewPublisher** -- [Azure Database for MySQL](https://azure.microsoft.com/en-us/products/mysql) **Database MySQL** -- [Azure Cache for redis](https://azure.microsoft.com/en-us/products/cache) **Redis** - [Azure Functions](https://azure.microsoft.com/en-us/products/functions) **Auth** -- [Azure Cache for redis](https://azure.microsoft.com/en-us/products/cache) **Redis** -- [Azure Database for MySQL](https://azure.microsoft.com/en-us/products/mysql) **Database MySQL** - [Azure Container Apps](https://azure.microsoft.com/en-us/products/container-apps) **Horizontal container with Review Reader** -- Redis and MongoDB **Phase 4 End to End flow between services** **Flow Diagram as Publisher Auth** - User as a **publisher** 1. User as a **publisher** will access to ReviewPublisher through API Management Azure or API Gateway. 2. Then API Management Azure will redirect the request to ReviewPublisher. Request will be handle first by API Management Azure and then by ReviewPublisher. 3. ReviewPublisher will handle the request; the first step will be authenticate the user through Auth service. 4. So ReviewPublisher will send a request to Auth service to authenticate the user. Auth service will handle the request and will send a response to ReviewPublisher. 5. Auth service looks into Azure Cache for redis if the user is authenticated or already exists. 6. If the user is authenticated or already exists, Auth service will send a response to ReviewPublisher. 7. If the user is not into Azure Cache for redis, Auth service will do a query to MySQL Database and will send a response to ReviewPublisher. 8. ReviewPublisher will handle the response and will send a response to API Management Azure. 9. User as a **publisher** will get a response from ReviewPublisher through API Management Azure and will be able to create, edit and remove reviews of cameras if the user is authenticated. ![Flow diagram as a publisher](https://github.com/SebasttianDaza/ReviewApp/assets/81209181/4cef8d9d-eac3-48ce-87fc-cebaf9c7dfc6) **Flow Diagram as Publisher Create, Edit and Remove review** - User as a **publisher** 1. User as a **publisher** have to be authenticated to create, edit and remove reviews of cameras. If the user is not authenticated, look at the flow diagram as a publisher auth. 2. User as a **publisher** will create, edit and remove reviews of cameras through API Management Azure or API Gateway. 3. Then request will be handle first by API Management Azure and then by ReviewPublisher. 4. If the request is **Get reviews**, ReviewPublisher looks into Azure Cache for redis if the review already there and if so, ReviewPublisher will send a response to API Management Azure. Otherwise, ReviewPublisher will do a query to MySQL Database, save it in Azure Cache for redis and return the response to API Management Azure. 5. If the request is **Create review**, ReviewPublisher looks into Azure Cache for redis if the review already exists and otherwise, ReviewPublisher will do a query to MySQL Database, save it in Azure Cache for redis and return the response to API Management Azure. 6. If the request is **Edit review**, ReviewPublisher will do a query to MySQL Database, update it in Azure Cache for redis and return the response to API Management Azure 7. If the request is **Remove review**, ReviewPublisher will do a query to MySQL Database, delete it in Azure Cache for redis and return the response to API Management Azure ![Flow diagram as a publisher create, edit and remove review](https://github.com/SebasttianDaza/ReviewApp/assets/81209181/85bb34b2-0c37-4858-bb46-ef42e8103e9d) **Flow diagram as a reader** - User as a **reader** 1. User as a **reader** doesn't have access or be authenticated, so it'll be able to get content of reviews of cameras. 2. User as a **reader** will get content of reviews of cameras through API Management Azure or API Gateway. 3. Then request will be sent to Azure Load Balancer and it'll redirect some server into horizontal container about their criterion. 4. ReviewPublisher get the request, get the response from Redis or MongoDB and return the response to API Management Azure. 5. Finally user as a **reader** get response from API Management Azure. ![Flow diagram as a reader](https://github.com/SebasttianDaza/ReviewApp/assets/81209181/5c30d204-52ac-4ad9-b48c-fa583b56e9e0) **Flow diagram as a publisher Auth in local soon** **Flow diagram as a reader in local soon** ### Data model Soon ### Limitations & Unknowns - Email notifications - Not support **Review publisher** to create reviews in another continent - Users(**readers**) can't login and register - **Payment gateway** to pay for the reviews - Search|Lookup functionality for reviews - Not authentication to get reviews - Migrate a lot of data from NoSQL Database when Horizontal scaling will get many instances of MySQL Database, Will it be a problem? Will it be slower? ### Data structures ### Costs