LLM Local Deployment: Model Selection and Multi-Instance Load Balancing
This article explains how to select a model for local LLM deployment and how to scale a single inference service across multiple instances. It covers a four-dimension selection framework, the parallelism limits of a single inference process, a reverse proxy architecture that exposes one port for multiple backends, Nginx configuration for streaming output, and the stability and observability practices needed in production.
1. Why Local Deployment Has Become a Must-Have
Driven by data compliance, network isolation, low latency, and predictable long-term cost, more and more teams are choosing to run large language models in their own environments. Compared with calling an external service, local deployment keeps data inside your own perimeter, gives you full control over the request path, and allows deep customization. The trade-off is that you now own hardware planning, inference engine tuning, service orchestration, and stability.
A common mistake is to “pick the model first and think about the architecture later.” The safer order is the reverse: define what the business needs in terms of context length, concurrency, time to first token, and output style; work backward to the GPU memory and parallelism strategy; and only then decide the service topology. Otherwise you easily end up with a model that runs but cannot meet throughput targets, or one that fills up GPU memory and still cannot scale horizontally.
2. A Decision Framework for Model Selection
Selection is not about chasing parameter counts. Evaluate candidates quantitatively along four dimensions.
- GPU memory usage: The memory limit is determined jointly by the weights and the key-value cache of concurrent requests. The longer the context and the higher the concurrency, the more significant the cache overhead, so leave headroom to avoid overflow.
- Throughput and latency: Separate time to first token from overall generation speed. Interactive applications should prioritize a low time to first token, while batch jobs care more about total output per unit of time.
- Capability fit: Code, summarization, extraction, and multi-turn dialogue place different demands on the model. Compare candidates on a small scale using your own evaluation set rather than relying on generic leaderboards.
- Engineering ecosystem: Support for common quantization formats, a streaming output interface, and the ability to integrate with your existing gateway and monitoring stack directly affect the cost of getting into production.
The practical advice is to start with a mid-size model to get the whole path working, then scale up or add replicas gradually based on real traffic, instead of betting everything at once.
3. The Parallelism Limits of a Single Inference Instance
The single-instance architecture of mainstream local inference frameworks is typically “one service process serving one complete copy of the model.” It does not natively provide multi-replica data parallelism, but you can choose the deployment shape based on memory needs: run on a single GPU when memory is sufficient, or use tensor parallelism to split the model across multiple GPUs when it is not.
Take 8 GPUs as an example. If each replica occupies 2 GPUs (tensor parallelism of 2), you need to start 4 independent inference service processes, each listening on a different port. The question then arises: should callers maintain their own port list and remove failed nodes themselves? Clearly not. The right approach is to put a reverse proxy in front, expose a single port, and distribute requests evenly across the backend instances.
4. Overall Architecture and Traffic Path
The overall path is straightforward: clients access port 80 uniformly; the reverse proxy acts as the load balancing layer and distributes requests to the 4 backend inference instances; each instance in turn uses 2 GPUs through tensor parallelism. This brings three benefits: callers are unaware of backend topology changes; a failed instance is removed automatically; and scaling out only requires adding instances and updating the upstream list.
5. Deploying the Reverse Proxy (Using a General Package Manager)
On Ubuntu/Debian systems, update the package sources first, install the reverse proxy with the system package manager, then confirm the installation with the version command. In production, pin the version and bring it under configuration management to avoid environment drift.
# Update package sourcessudo apt update# Install the reverse proxysudo apt install nginx -y# Confirm the versionnginx -v
6. Key Load Balancing Configuration Points
The main configuration file is usually at /etc/nginx/nginx.conf, but the best practice is to create a separate file under /etc/nginx/conf.d/ for easier version control and gradual rollouts.
upstream vllm_backend {# Default round-robin policy; switch to least connections if neededserver 127.0.0.1:8000 max_fails=3 fail_timeout=30s;server 127.0.0.1:8001 max_fails=3 fail_timeout=30s;server 127.0.0.1:8002 max_fails=3 fail_timeout=30s;server 127.0.0.1:8003 max_fails=3 fail_timeout=30s;keepalive 256; # Reuse long-lived connections to reduce handshake overhead}server {listen 80;server_name _; # Or use your own domainclient_max_body_size 20M; # Prevent long prompts from being truncatedlocation / {proxy_pass http://vllm_backend;proxy_buffering off; # Disable buffering, otherwise streaming output breaksproxy_cache off;proxy_connect_timeout 300s;proxy_send_timeout 300s;proxy_read_timeout 300s;proxy_http_version 1.1; # Support long-lived connectionsproxy_set_header Connection '';proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;chunked_transfer_encoding off; # Compatible with streaming chunked transfer}}
Four settings in this configuration are the easiest to overlook yet must be correct:
- Disable proxy buffering. With buffering enabled, data is held until a batch is complete before being sent, and the token-by-token effect of streaming output disappears.
- Extend the timeouts. Long-text generation can take far longer than the defaults, or you will see frequent 504 errors.
- Use HTTP/1.1 and clear the Connection header, which, together with upstream keepalive, is what actually enables connection reuse.
- Allow a larger request body, so long prompts and document fragments are not rejected.
7. Completing Stability and Observability
Load balancing is only the starting point. Production also needs active health checks or an out-of-band probe, so requests are not sent to instances that have not finished loading weights; warm-up requests when an instance starts, to reduce cold-start jitter on the first request; unified log and metric collection covering at least request volume, error rate, queueing time, GPU memory usage, and the distribution of generation lengths; and a sensible concurrency limit and queueing policy at the gateway layer to prevent overload cascades. If you later need to scale across machines, replace the upstream list with addresses of multiple hosts and bring in a container platform and a configuration center to manage instance lifecycles uniformly.
8. Summary
The key to local LLM deployment is not piling up GPUs, but aligning the three things—model shape, parallelism strategy, and service topology. Choose the model and parallelism based on memory and use case, converge multiple instances into a single entry point with a reverse proxy, and finally hold up stability for long-text and streaming scenarios with timeouts, buffering, health checks, and monitoring. This approach scales smoothly from a single machine with multiple GPUs to multiple machines with multiple replicas, leaving plenty of room for future capacity expansion.
