Microservice Architecture - CSCI-40500-77100-Spring-2021/project-10__backend GitHub Wiki

Microservice

Diagram

Microservice Diagram

Description of Services

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.

API Gateway

Receives all HTTP requests, authenticates them, and directs them to api request handler

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

Cognito

  • 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

User Query Service

Interface between Cognito and the rest of the service for admin user management

Image Upload Handler

Used to upload base64 encoded images and generate a public url

CloudWatch Logging and Metrics

  • 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

Communication

  • 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.

Authentication

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.

Generate the token yourself

Requirements:

  • NodeJS: https://nodejs.org/en/

  • Typescript

    npm install -g typescript
    npm install -g ts-node
  • Yarn: npm install -g yarn

Steps:

  1. Clone our repository: git clone https://github.com/CSCI-40500-77100-Spring-2021/project-10__backend.git

  2. Navigate to scripts directory: cd project-10__backend/scripts

  3. Install dependencies: yarn install

  4. Create a .env file in the root of the scripts directory and the following

    AWS_REGION=us-east-1
    COGNITO_USER_POOL_ID=us-east-1_fhF5vq3fZ
    USER_POOL_CLIENT_ID=7bc5l2j1ei8eieijeijvdormeq
  5. 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

Sample Routes

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 preview 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

      1. API Gateway Receives Requests
      2. API Gateway authenticates Request by calling Cognito
      3. API Gateway redirects requests to API Request Handler
      4. API Request Handler calls User Query Service for find user by username
      5. User Query Service checks cognito to see if the user exists
      6. 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
  • 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

      1. API Gateway Receives Requests
      2. API Gateway authenticates Request by calling Cognito
      3. API Gateway redirects requests to API Request Handler
      4. API Request Handler Queries DynamoDB for any matching entries
      5. Communication are backtracked and response is sent to API Requester

Data Inconsistency

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

⚠️ **GitHub.com Fallback** ⚠️