A simplified, functional prototype of a distributed document search service built with Node.js, Elasticsearch, and Redis. This prototype demonstrates core multi-tenancy and search capabilities with a minimal footprint.
- 🔍 Full-text search using Elasticsearch
- 🏢 Multi-tenancy with logical isolation (Tenant ID injection)
- ⚡ Caching using Redis for search results
- 🛡️ Rate limiting per tenant
- 🐳 Docker-ready setup
┌──────────────┐ ┌─────────────┐ ┌──────────────────┐
│ Clients │────▶│ API Layer │────▶│ Elasticsearch │
│ │ │ (Node.js) │ │ (Search Engine) │
└──────────────┘ └──────┬──────┘ └──────────────────┘
│
┌──────┴──────┐
▼ ▼
┌───────────┐ ┌────────────┐
│ Redis │ │ Single │
│ (Cache) │ │ Index/POD │
└───────────┘ └────────────┘
- Node.js 18+
- Docker and Docker Compose
cd distributed-document-search
npm installdocker-compose up -dnpm run build
npm startThe server will start on port 3000.
All requests must include the Tenant ID via header or query parameter:
- Header:
X-Tenant-ID: <tenant-id> - Query:
?tenant=<tenant-id>
POST /documents
X-Tenant-ID: tenant-a
Content-Type: application/json
{
"title": "My Document",
"content": "This is some content for the document."
}GET /search?q=content
X-Tenant-ID: tenant-aGET /documents/{id}
X-Tenant-ID: tenant-aDELETE /documents/{id}
X-Tenant-ID: tenant-aGET /healthEnvironment variables are defined in .env (or default values used in src/config.ts):
| Variable | Default | Description |
|---|---|---|
PORT |
3000 | API server port |
ELASTICSEARCH_NODE |
http://localhost:9200 | Elasticsearch URL |
REDIS_HOST |
localhost | Redis host |
REDIS_PORT |
6379 | Redis port |
RATE_LIMIT_MAX |
20 | Max requests per minute per tenant |
distributed-document-search/
├── src/
│ ├── config.ts # Configuration
│ ├── index.ts # Entry point
│ ├── controllers/ # Route handlers
│ │ ├── documents.controller.ts
│ │ └── search.controller.ts
│ ├── middleware/ # Tenant & Rate Limit middleware
│ │ └── index.ts
│ └── services/ # Business logic
│ ├── elasticsearch.service.ts
│ └── cache.service.ts
├── docker-compose.yml # Infrastructure (ES + Redis)
├── Dockerfile # API container
├── package.json
└── tsconfig.json
MIT