Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
/ UserDataLink Public archive

RPC based User Service with Search functionality

Notifications You must be signed in to change notification settings

ansh-devs/UserDataLink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Service with Search Functionality using gRPC as transportation layer

Software Architecture Patterns and paradiagms used -

  • Repository Pattern → used in Repository-Layer/Database layer inside the internal/database directory to make business logic and database layer logic decoupled. In future if needed just make the struct and implement the UserRepository interface to the desired database (Postgres/Cassandra/MongoDb) such that there will be no need to make any changes in the UserService Service layer.
  • Separation Of Concern (from SOLID) → there is a separation between the transportation layer gRPC and the Service layer and the repository layer
  • Dependency Inversion Principle (from SOLID) → Dependency of UserRepository is injected in the UserService to perform Db-calls.
  • Builder Pattern from Design Principles → used in the constructor of the UserService which itself configure the gRPC's Reflection and bind the PORT to the service.
  • Idiomatic practices encouraged by the Golang Community → efficient use of maps, slices etc.

Protocol Buffers v3 Definition

  • UserService Proto Definition-
+-------------+--------------------+---------------------------+----------------------------+
|   SERVICE   |        RPC         |       REQUEST TYPE        |       RESPONSE TYPE        |
+-------------+--------------------+---------------------------+----------------------------+
| UserService | GetUserById        | GetUserByIdRequest        | GetUserByIdResponse        |
| UserService | GetUsersListByIds  | GetUsersListByIdsRequest  | GetUsersListByIdsResponse  |
| UserService | GetUsersByCriteria | GetUsersByCriteriaRequest | GetUsersByCriteriaResponse |
+-------------+--------------------+---------------------------+----------------------------+
  • Available Proto Message Types-
+----------------------------+
|          MESSAGE           |
+----------------------------+
| GetUserByIdRequest         |
| GetUserByIdResponse        |
| GetUsersByCriteriaRequest  |
| GetUsersByCriteriaResponse |
| GetUsersListByIdsRequest   |
| GetUsersListByIdsResponse  |
+----------------------------+
  • GetUserById RPC types-

    • Request
    +-------+------------+----------+
    | FIELD |    TYPE    | REPEATED |
    +-------+------------+----------+
    | id    | TYPE_INT64 | false    |
    +-------+------------+----------+
    
    
    • Response
    +-------+---------------------+----------+
    | FIELD |        TYPE         | REPEATED |
    +-------+---------------------+----------+
    | user  | TYPE_MESSAGE (User) | false    |
    +-------+---------------------+----------+
    
  • GetUsersListByIds RPC types-

    • Request
    +-------+------------+----------+
    | FIELD |    TYPE    | REPEATED |
    +-------+------------+----------+
    | ids   | TYPE_INT64 | true     |
    +-------+------------+----------+
    
    
    • Response
    +-------+---------------------+----------+
    | FIELD |        TYPE         | REPEATED |
    +-------+---------------------+----------+
    | users | TYPE_MESSAGE (User) | true     |
    +-------+---------------------+----------+
    
  • GetUsersByCriteria RPC types-

    • Request
    +-------+---------------------------+----------+
    | FIELD |           TYPE            | REPEATED |
    +-------+---------------------------+----------+
    | type  | TYPE_ENUM (UserCriterias) | false    |
    | value | TYPE_STRING               | false    |
    +-------+---------------------------+----------+
    
    
    • Response
    +-------+---------------------+----------+
    | FIELD |        TYPE         | REPEATED |
    +-------+---------------------+----------+
    | users | TYPE_MESSAGE (User) | true     |
    +-------+---------------------+----------+
    

For the request and response of RPC calls checkout the user_service.proto

  • Grpc Interceptor Logging for Incoming Requests alt-logging-image

Environment Variable

To run this project, The environment variable PORT must be in the accessible scope which is used to set the port where the gRPC server will be listening for the incoming connections.

Steps To Run

  • Without Docker in Linux/WSL Environment:
    • make run - will execute the source code.
    • make build - will build the executable binary from the source code.
  • With Docker:
    • docker build . -t user-service - will build image from Dockerfile.
    • docker run -d --restart=always -p 8080:8080 user-service - will run the image inside container.

About

RPC based User Service with Search functionality

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published