A high-performance, distributed chat system built with a microservices architecture. The system handles message creation through an event-driven pipeline using Go for high-throughput message ingestion, Rails for business logic, Redis for queuing, and Elasticsearch for full-text search.
βββββββββββ ββββββββββββ βββββββββββ ββββββββββββββ βββββββββββββ
β Client ββββββΆβ Nginx ββββββΆβ Go ββββββΆβ Redis ββββββΆβ Sidekiq β
βββββββββββ β Gateway β β Service β β Queue β β Worker β
ββββββββββββ βββββββββββ ββββββββββββββ βββββββ¬ββββββ
β β
β βΌ
β βββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββΆβ Rails API Service β
β - REST API endpoints β
β - Business logic & validations β
β - Database operations β
ββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββΌββββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββ ββββββββββββββββ ββββββββββββββββ
β MySQL β β Redis β βElasticsearch β
βDatabase β β (Sequences) β β (Search) β
βββββββββββ ββββββββββββββββ ββββββββββββββββ
- Nginx: API gateway with rate limiting (10 req/s, burst 20) and request routing
- Go Service: High-performance message ingestion service that queues messages to Redis
- Rails API: RESTful API for managing applications, chats, and messages
- Sidekiq Worker: Background job processor that consumes messages from Redis queue
- MySQL: Primary database for persistent storage
- Redis: Message queue and distributed sequence generation
- Elasticsearch: Full-text search engine for message search functionality
- Fields:
name,token(UUID),chats_count - Purpose: Top-level entity representing a client application
- Token: Auto-generated UUID for API authentication
- Fields:
application_id,number,messages_count - Purpose: Conversation threads within an application
- Numbering: Sequential per application (1, 2, 3...)
- Fields:
chat_id,number,body - Purpose: Individual messages within a chat
- Numbering: Sequential per chat using Redis atomic counters
- Search: Indexed in Elasticsearch for full-text search
- Docker & Docker Compose
- Git
-
Clone the repository
git clone https://github.com/aroo530/luciq-distributed-chat-system.git cd luciq-distributed-chat-system -
Start all services
docker-compose up --build
This will start:
- MySQL (port 3306)
- Redis (port 6379)
- Elasticsearch (port 9200)
- Rails API (port 3000)
- Sidekiq Worker
- Go Service (port 8080)
- Nginx Gateway (port 80)
-
Verify services are running
docker-compose ps
All services should show as "Up" or "healthy"
-
Create the database (if not auto-created)
docker-compose exec rails bundle exec rails db:create db:migrate
docker-compose downTo remove volumes (data will be lost):
docker-compose down -vTip: You can import the
Luciq Chat System API.postman_collection.jsonfile into Postman to easily test all API endpoints.
| Method | Endpoint | Description |
|---|---|---|
| POST | /applications |
Create a new application |
| GET | /applications |
List all applications |
| GET | /applications/:token |
Get application details |
| PATCH | /applications/:token |
Update application name |
| Method | Endpoint | Description |
|---|---|---|
| POST | /applications/:token/chats |
Create a new chat |
| GET | /applications/:token/chats |
List all chats for an application |
| GET | /applications/:token/chats/:number |
Get chat details |
| Method | Endpoint | Description |
|---|---|---|
| POST | /messages |
Create a message (via Go service) |
| GET | /applications/:token/chats/:number/messages |
List messages in a chat |
| GET | /applications/:token/chats/:number/messages/search?q=query |
Search messages |
-
Create an application
curl -X POST http://localhost/applications \ -H "Content-Type: application/json" \ -d '{"name": "MyApp"}'
Response:
{ "token": "token", "name": "MyApp", "chats_count": 0 } -
Create a chat
curl -X POST http://localhost/applications/token/chats \ -H "Content-Type: application/json" -
Send a message (via Go service)
curl -X POST http://localhost/messages \ -H "Content-Type: application/json" \ -d '{ "application_token": "token", "chat_number": 1, "body": "Hello, World!" }'
-
Search messages
curl "http://localhost/applications/token/chats/1/messages/search?q=Hello"
The project uses RSpec for testing:
Run all tests:
docker-compose exec rails bundle exec rspecRun specific test file:
docker-compose exec rails bundle exec rspec spec/requests/messages_spec.rbRun tests with coverage report:
docker-compose exec rails bundle exec rspec
# Coverage report will be generated in coverage/index.html- Factory Bot: Test data generation
- Faker: Random test data
- Database Cleaner: Test isolation
- SimpleCov: Code coverage reporting
- RSpec: Testing framework
RAILS_ENV: Environment (development/test/production)DATABASE_URL: MySQL connection stringREDIS_URL: Redis connection for SidekiqELASTICSEARCH_URL: Elasticsearch endpoint
REDIS_URL: Redis connection for message queueRAILS_API_URL: Rails API endpointLOG_LEVEL: Logging level (info/debug/error)
MySQL credentials (development):
- Host: localhost:3306
- Database: luciq_development
- User: luciq
- Password: password
- Root Password: root
- Client sends POST request to
/messagesvia Nginx - Nginx routes to Go service (rate-limited)
- Go Service validates the request and enqueues the job to Redis
- Sidekiq Worker (MessageConsumerWorker) picks up the job
- Worker generates message number using Redis INCR
- Worker saves message to MySQL database
- Worker triggers ChatCounterWorker to update counts
- Message is indexed in Elasticsearch for search
- Format: JSON with correlation IDs
- Location:
/var/log/nginx/access.log - Fields: timestamp, remote_addr, request_id, status, upstream
- Rails: Structured logging with Lograge
- Go: Structured logging with context
- Sidekiq: Job execution logs
# Nginx logs
docker-compose logs -f nginx
# Rails logs
docker-compose logs -f rails
# Go service logs
docker-compose logs -f go_service
# Sidekiq worker logs
docker-compose logs -f worker.
βββ docker-compose.yml # Service orchestration
βββ nginx/
β βββ conf.d/
β βββ luciq.conf # Nginx routing & rate limiting
βββ go/
β βββ main.go # Go service entry point
β βββ handlers/ # HTTP handlers
β βββ queue/ # Redis queue integration
β βββ logging/ # Structured logging
βββ rails/
β βββ app/
β β βββ controllers/ # API controllers
β β βββ models/ # ActiveRecord models
β β βββ jobs/ # Sidekiq workers
β βββ config/ # Rails configuration
β βββ db/
β β βββ migrate/ # Database migrations
β β βββ schema.rb # Database schema
β βββ spec/ # RSpec tests
βββ data/ # Persistent data (gitignored)
docker-compose exec rails bundle exec rails generate migration MigrationName
docker-compose exec rails bundle exec rails db:migratedocker-compose exec rails bundle exec rails consoledocker-compose exec redis redis-clidocker-compose exec mysql mysql -u luciq -ppassword luciq_development| Component | Technology | Version |
|---|---|---|
| API Framework | Ruby on Rails | 7.1.3 |
| Go Framework | Chi Router | v5 |
| Database | MySQL | 8.0 |
| Cache/Queue | Redis | 7-alpine |
| Search | Elasticsearch | 8.14.1 |
| Background Jobs | Sidekiq | Latest |
| Web Server | Nginx | Latest |
| Testing | RSpec | Latest |