Make sure you have docker installed on your machine.
docker-compose up --scale instabug-chat=3
Note: As Ruby on Rails is a fully featured framework, I used a mini framework in GoLang to build the task faster.
- Attached is a postman collection that you can use to test the API. in the top level directory of the project
- NGINX - Reverse proxy server that loads balance requests to the API.
- Go API - Handles requests
- Elasticsearch - Used to index the messages for search functionality.
- MySQL - Main datastore for the application.
- Redis - Used for caching the
chats
andmessages
data, it caches the GET list only [for simplicity] - RabbitMQ - Used for handling the messages creation between the API and the Worker.
- Go Worker - Worker that handles the message creation.
- Event/Listener - Used to handle the message creation event to store indexed data in Elasticsearch.
- Unit Tests - Unit tests for Application service
go test ./tests/unit/services/
.
GET /applications
POST /applications
GET /applications/:Token
PUT /applications/:Token
POST /applications/:Token/chats
GET /applications/:Token/chats
GET /applications/:Token/chats/:ChatNumber
POST /applications/:Token/chats/:ChatNumber/messages
GET /applications/:Token/chats/:ChatNumber/messages
GET /applications/:Token/chats/:ChatNumber/messages/:MessageNumber
PUT /applications/:Token/chats/:ChatNumber/messages/:MessageNumber
-
Preventing collisions of
chat_number
per application andmessage_number
per chat by using Compound Indexes in the database. -
Handling race conditions in getting the
chat_number
andmessage_number
by using select for update in transactions.
Note: All system components are put together in the same structure for simplicity.
- api - Go API, you can find the routes, controllers, services, and models.
- worker - Go Worker, you can find the worker that handles the message creation in
./pkg/rabbitmq/message_worker.go
- postman-collection - Postman collection for the API in
./ChatSys.postman_collection.json
- unit-tests - Unit tests for Application service in
./tests/unit/services/