# Multi-Instance Deployment Guide This document provides guidance for deploying multiple instances of each service for high availability and scalability. ## Overview All services in this distributed network mapping system are designed to support multi-instance deployments, but each has specific considerations and limitations. --- ## Input Service (input_service/) ### Multi-Instance Readiness: ⚠️ **Partially Ready** #### How It Works - Each instance maintains its own per-consumer state and CIDR generators - State is stored locally in `progress_state/` directory - Global hop deduplication (`globalSeen` map) is **instance-local** #### Multi-Instance Deployment Strategies **Option 1: Session Affinity (Recommended)** ``` Load Balancer (with sticky sessions based on source IP) ├── input_service instance 1 ├── input_service instance 2 └── input_service instance 3 ``` - Configure load balancer to route each ping worker to the same input_service instance - Ensures per-consumer state consistency - Simple to implement and maintain **Option 2: Broadcast Hop Submissions** ``` output_service ---> POST /hops ---> ALL input_service instances ``` Modify output_service to POST discovered hops to all input_service instances instead of just one. This ensures hop deduplication works across instances. **Option 3: Shared Deduplication Backend (Future Enhancement)** Implement Redis or database-backed `globalSeen` storage so all instances share deduplication state. #### Known Limitations - **Hop deduplication is instance-local**: Different instances may serve duplicate hops if output_service sends hops to only one instance - **Per-consumer state is instance-local**: If a consumer switches instances, it gets a new generator and starts from the beginning - **CIDR files must be present on all instances**: The `cloud-provider-ip-addresses/` directory must exist on each instance #### Deployment Example ```bash # Instance 1 ./http_input_service & # Instance 2 (different port) PORT=8081 ./http_input_service & # Load balancer (nginx example) upstream input_service { ip_hash; # Session affinity server 127.0.0.1:8080; server 127.0.0.1:8081; } ``` --- ## Output Service (output_service/) ### Multi-Instance Readiness: ✅ **Fully Ready** #### How It Works - Each instance maintains its own SQLite database - Databases are independent and can be aggregated later - `sentHops` deduplication is instance-local with 24-hour TTL #### Multi-Instance Deployment ``` ping_service workers ---> Load Balancer ---> output_service instances ``` - No session affinity required - Each instance stores results independently - Use `/dump` endpoint to collect databases from all instances for aggregation #### Aggregation Strategy ```bash # Collect databases from all instances curl http://instance1:8091/dump > instance1.db curl http://instance2:8091/dump > instance2.db curl http://instance3:8091/dump > instance3.db # Merge using sqlite3 sqlite3 merged.db <