Docker and docker compose should be installed on the system
- Clone the repository
git clone https://github.com/puneet222/media.git
- Run docker compose command
docker compose up -d
- REST Endpoint to fetch the value of a given key
curl 'http://localhost:8088/data?key=key1'
Key will be passed as query params to the url
- Websocket API
http://localhost:8088/ws
URL for websocket connection
{
"key": "key1",
"value": "value1"
}
Request Message to be sent over to websocket
{
"success": true
"message": string
}
Response message received from websocket
To handle multiple concurrent requests to the server for saving key-value pairs, I'm using the sync.Mutex package in Go.
I'm utilizing MongoDB for persistent storage of key-value pairs to ensure they are saved across server restarts.
To improve performance, I'm using a new Go routine to save the same key-value pair in MongoDB asynchronously after saving it in the in-memory data store:
go app.InsertToDB(keyValue)
- Instead of utilizing an in-memory data store (e.g. a map), we could consider using Redis to store key-value pairs.
- While I have been occupied with work, I am currently conducting tests on the database (DB) and will ensure the repository is complete by adding the remaining tests.
- For our assignment, we could also opt to use the file system instead of MongoDB for persistent storage.
- As for testing the REST API and WebSocket API, I utilized Postman.