Microservice Architecture - CSCI-40500-77100-Spring-2021/project-10__backend GitHub Wiki
We have various micro-services in our architecture. The publicly accessible services are API Gateway and Cognito. Cognito has various functionalities that are public and private. All our services are lightweight, implementation-independent, independently deployable. API Request Handler has various dependencies, thus it isn't self-contained.
Receives all HTTP requests, authenticates them, and directs them to api request handler
API Request Handler is the main component that is responsible for routing and handling a given incoming request. It has access to an a DynamoDB Table for storing user gallery informations
- Allows app clients (iOS and Android App) to signup, login and generate access token (ID Token, Access Token, and Refresh Tokens)
- Allows API Gateway to validate an incoming request token
- Allows User Query Service to list users and get users by their username
Interface between Cognito and the rest of the service for admin user management
Used to upload base64 encoded images and generate a public url
- API Gateway logs incoming requests
- API Request Handler, Image Upload Handler, and User Query Handler logs debug information for incoming requests
- Generates metrics for traffic to each services
- API URL: https://dbkw974ay1.execute-api.us-east-1.amazonaws.com
- All communications that requires a response are synchronous, such that when a request is made a connection stays open for a duration of time, waiting for response. There are no internal or external queues. However, there are no blocking code during code execution. Waiting for response happens on a separate thread, allowing each service to continue processing any additional requests.
Our API is protected using Token based authorization. As such, you will need to provide an Authorization
header to each requests.
Each token has a lifespan of 1 hour so I am not able to add a valid token in this assignment. There are two ways you can get this token during grading. You can either email me at [email protected] during grading. The alternative is to setup our backend repository which contains a script for generating token yourself.
Requirements:
-
NodeJS: https://nodejs.org/en/
-
Typescript
npm install -g typescript npm install -g ts-node
-
Yarn:
npm install -g yarn
Steps:
-
Clone our repository:
git clone https://github.com/CSCI-40500-77100-Spring-2021/project-10__backend.git
-
Navigate to scripts directory:
cd project-10__backend/scripts
-
Install dependencies:
yarn install
-
Create a
.env
file in the root of the scripts directory and the followingAWS_REGION=us-east-1 COGNITO_USER_POOL_ID=us-east-1_fhF5vq3fZ USER_POOL_CLIENT_ID=7bc5l2j1ei8eieijeijvdormeq
-
Generate a token:
yarn run file user/get_token.ts -d
This token is generated for a user with username defaultuser
who has a user id of 062884cb-aa16-4394-a5d7-fdcd532b5efb
Pre-created Requests from Postman
If you have postman, you can simply import the following connection to postman, which contains the three routes that's described below in the "Requests FROM CURL" section below.
You will need to provider a valid authorization header to make a request.
Example:
Postman Collection File:
MealSnapMicroServiceAssignment.postman_collection.json
Requests From CURL
- Find user by username
-
Type: GET
-
Route:
/search/user?username=<search-user-username>
-
Example curl
curl --location --request GET 'https://dbkw974ay1.execute-api.us-east-1.amazonaws.com/prod/search/user?username=defaultuser' \ --header 'Authorization: <YOUR_AUTHORIZATION_HEADER>' \ --data-raw ''
-
In this request, the following communication happens
- API Gateway Receives Requests
- API Gateway authenticates Request by calling Cognito
- API Gateway redirects requests to API Request Handler
- API Request Handler calls User Query Service for find user by username
- User Query Service checks cognito to see if the user exists
- All communications are backtracked and response is send to API Requester (You)
-
- Generic User Search: Allows you to search a user with any matching characteristics of a query
-
Type: GET
-
Route:
/search/user?query=<searched-user>
-
Example curl to search for user "asif"
curl --location --request GET 'https://dbkw974ay1.execute-api.us-east-1.amazonaws.com/prod/search/user?query=asif' \ --header 'Authorization: <YOUR_AUTHORIZATION_HEADER>' \ --data-raw ''
-
Example: https://dbkw974ay1.execute-api.us-east-1.amazonaws.com/prod/search/user?username=defaultuser
-
The same communication steps in Find user by username are followed
-
- Get gallery photo for a user
-
Type: GET
-
Route:
/user/<userid>/gallery
-
Example curl to get gallery for user bbef86f0-ff93-4b1c-a210-ac7aea0f889b
curl --location --request GET 'https://dbkw974ay1.execute-api.us-east-1.amazonaws.com/prod/user/bbef86f0-ff93-4b1c-a210-ac7aea0f889b/gallery' \ --header 'Authorization: <YOUR_AUTHORIZATION_HEADER>' \ --data-raw ''
-
In this request, the following communication happens
- API Gateway Receives Requests
- API Gateway authenticates Request by calling Cognito
- API Gateway redirects requests to API Request Handler
- API Request Handler Queries DynamoDB for any matching entries
- Communication are backtracked and response is sent to API Requester
-
There aren't any data inconsistency issues in our app. The only thing that are are duplicating between our services is the a given user's userid
, which is immutable. As such, this duplication doesn't require any data consistency mechanisms