A generic distributed processing system using NATS JetStream for message routing and supporting multiple service types (PDF processing, image analysis, text processing, etc.).
Infrastructure Server Processing Servers Client Applications
(NATS) (GPU, CPU, etc.) (Laptop, Web, etc.)
| | |
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ NATS โโโโโโโโโบโ PDF Worker โ โ Your App โ
โ JetStream โ โ Image Workerโโโโโโโโโโโโโโบโ (services.pyโ
โ Message โ โ Text Worker โ โ thinktank2) โ
โ Broker โ โ ... โ โ ... โ
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ โ โ
Pure Messaging Business Logic Submit Requests
ct/
โโโ infrastructure/ # ๐๏ธ Infrastructure components
โ โโโ nats-server/ # Pure NATS server (dedicated server)
โโโ pdf/ # ๐ PDF processing service (GPU server)
โ โโโ docling_worker.py # Worker process
โ โโโ services.py # Client library
โ โโโ tests/ # Service tests
โโโ future_services/ # ๐ฎ Add more services as needed
โโโ image_processing/
โโโ text_analysis/
โโโ audio_transcription/
On your dedicated NATS server:
cd infrastructure/nats-server/
./setup.sh
# Save the generated token - you'll need it for all services!On your GPU server:
cd pdf/
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Configure environment
cp environment_config.txt .env
# Edit .env with NATS server IP and token
# Start docling worker (docs.process.*)
./start_worker.sh
# Optional: GLiNER KG infer (kg.infer) โ same venv + extra deps
pip install -r requirements-gliner.txt
./start_kg_gliner.shGPU deploy (both workers): push to climateandtech/pdf main, then from coolify-provisioning/ run ./gpu-setup-production.sh (once) and ./gpu-deploy-worker.sh. See docs/GPU_PRODUCTION.md.
Platform calls kg.infer when KG_EXTRACT_ON_GPU=1 (no separate platform clone on GPU).
Connect your existing services.py:
# In your thinktank2 project
from pdf.services import DocumentService
# Configure to point to your NATS server
doc_service = DocumentService()
await doc_service.setup()
result = await doc_service.process_document(
s3_key="documents/my-file.pdf",
docling_options={...}
)# Pure NATS configuration - no service specifics
NATS_TOKEN=your-generated-secure-token# Points to your infrastructure
NATS_URL=nats://your-nats-server-ip:4222
NATS_TOKEN=your-generated-secure-token
# Service-specific settings
AWS_ACCESS_KEY_ID=your-s3-credentials
# ... etcEach service type gets its own namespace on the shared NATS server:
| Service Type | Stream Name | Subject Prefix | Worker Group |
|---|---|---|---|
| PDF Docling | PDF_PROCESSING |
pdf.docling.* |
pdf_docling_workers |
| Image Processing | IMAGE_PROCESSING |
image.process.* |
image_workers |
| Text Analysis | TEXT_ANALYSIS |
text.analyze.* |
text_workers |
| Audio Transcription | AUDIO_TRANSCRIPTION |
audio.transcribe.* |
audio_workers |
- NATS Server: 1 dedicated server
- PDF Processing: 1 GPU server
- Clients: Your laptop
- NATS Cluster: 3 servers (HA)
- PDF Workers: Multiple GPU servers (auto-scaling)
- Image Workers: Multiple CPU servers
- Clients: Web applications, mobile apps, etc.
- NATS: Local Docker container
- Workers: Local processes
- Clients: Local development
- Token Authentication: Secure token for NATS access
- Network Isolation: Firewall rules for known IPs only
- TLS: Optional TLS encryption for production
- Separate Concerns: Infrastructure vs. business logic
- Create service directory:
mkdir new_service/ - Implement worker: Use existing patterns from
pdf/ - Configure namespace: Add to
generic_config.py - Deploy: On appropriate servers (GPU, CPU, etc.)
- Connect: All services use the same NATS infrastructure
- Infrastructure Setup - NATS server deployment
- Architecture Guide - Detailed system design
- PDF Service - PDF processing specifics
# Test infrastructure
cd infrastructure/nats-server/
# Connection tests included in setup
# Test PDF service
cd pdf/
pytest tests/ -v
# Test end-to-end
python -c "
import asyncio
from services import DocumentService
async def test():
service = DocumentService()
await service.setup()
print('โ
Connected to distributed system!')
asyncio.run(test())
"โ
Scalable: Add processing power by adding servers
โ
Flexible: Mix different service types on same infrastructure
โ
Reliable: Dedicated message infrastructure
โ
Maintainable: Clear separation of concerns
โ
Future-proof: Easy to add new processing capabilities
Perfect for: Multi-modal AI processing, distributed computing, microservices architecture