The History Service is designed to store and retrieve a user’s code submission history. Users can view their past submission records of a collaboration session, with details such as the submitted date, the question attempted on, and the matched username. The information on the submission is stored within the history service’s database, and the data is accessed through querying the history-service from the frontend. It uses Google Firestore as a cloud-based NoSQL database for efficient and scalable data storage and retrieval. It is developed with a RESTful API structure, allowing flexibility for client applications to interact with the service.
- Golang (Go): Statically typed, compiled language with low latency. Fast and efficient processing is ideal for high-read, high-write environments like in history service.
- Firebase Firestore: NoSQL Document database that is designed for automatic horizontal scaling and schema-less design that allows for flexibility as application grows and new features are added.
- REST Server: chi router was utilized which supports CORS, logging and timeout via middlewares. It is stateless, which reduces coupling and enhances scalability and reliability, simplicity and flexibility. For example, clients may make requests to different server instances when scaled.
- Docker: used to containerize the History Service to simplify deployment.
The submission history is organized with the most recent submission displayed first, making it easy for users to review their past submissions. Pagination is implemented to help users find specific records efficiently and reduce the amount of data transferred when loading the page.
On the question page, users can view their past submissions for that question, allowing them to see their submitted code alongside the question details for better context.
Each submission record is created through the execution service via an asynchronous call, ensuring smooth and efficient processing (more details provided in the next section).
The History Service is built with Go, utilizing Firestore as the database and Chi as the HTTP router. It allows for basic operations such as creating, reading, updating, and deleting question records.
- Create new collaboration history
- Read collaboration history by collaboration history ID
- Update collaboration history code
- Delete collaboration history
- Go (Golang)
- Firestore (Google Cloud Firestore)
- Chi (HTTP router)
- Go 1.16 or later
- Google Cloud SDK
- Firestore database setup in your Google Cloud project
-
Clone the repository
-
Set up your Firestore client
-
Install dependencies:
go mod tidy
- Create the
.env
file from copying the.env.example
, copying the firebase json key file into history-service directory, and fill in theFIREBASE_CREDENTIAL_PATH
with the path of the firebase credential JSON file.
To start the server, run the following command:
go run main.go
A message queue is used to pass submission results asynchronously from the execution-service to the history-service.
- In order to do so, we can run the following command to set up a docker container for RabbitMQ:
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
- Then we can run the history-service:
go run main.go
- We can run the execution-service by changing our directory and running the same command:
cd ../execution-service
go run main.go
To view more details on the RabbitMQ queue, we can go to localhost:15672
, and login using guest
as the username and password.
The server will be available at http://localhost:8082.
To run the application via Docker, run the following command:
docker build -t history-service .
docker run -p 8082:8082 -d history-service
The server will be available at http://localhost:8082.
POST: /histories
: Create a history record of the code submissionGET: /histories/{historyDocRefId}
: Reads the history record of the code submission, identified by the history reference IDGET: /histories/user/{username}
: Returns a paginated list of history records by a user, identified by the usernameGET: /histories/user/{username}/question/{questionDocRefId}
: Returns a paginated list of history records by a user, for a question, identified by the username and question reference ID
go run main.go