Proxies are the frontend of MLB. They listen on network addresses, speak specific protocols, and forward requests to backends.
A low-level TCP proxy that forwards raw bytes. It supports multiple prioritized sources (balancers or backend providers).
proxy "tcp" "my_tcp_proxy" {
sources = [
balancer.wrr.primary_balancer,
balancer.wrr.backup_balancer,
backends_inventory.static.maintenance_page
]
addresses = [":3306"]
connect_timeout = "2s"
close_on_backend_removal = true
}sources(list of strings, optional): A prioritized list of backend providers. The proxy will try to get a backend from each source in the order defined.source(string, optional, deprecated): The ID of the primary balancer. Used for backward compatibility; if defined, it is added as the first element of thesourceslist. Usesourcesinstead.backup_source(string, optional, deprecated): A secondary balancer used if the primary has no backends. Used for backward compatibility; if defined, it is added to thesourceslist aftersource. Usesourcesinstead.addresses(list of strings, required): Listening addresses.connect_timeout(duration string, optional): Timeout for connecting to the backend. Default:0s.client_timeout(duration string, optional): Idle timeout for the client connection. Default:0s.server_timeout(duration string, optional): Idle timeout for the backend connection. Default:0s.close_timeout(duration string, optional): Grace period for closing connections during shutdown. Default:0s.timeout_margin(duration string, optional): A small margin added to deadlines to prevent race conditions between client and server timeouts. Default:1s.buffer_size(number or string, optional): Proxy buffer size in bytes. Supports human-readable suffixes likekb,mb,gb(e.g.,"16kb"). Default:32768.close_on_backend_removal(boolean, optional): Iftrue, client connections are closed if the backend they are connected to is removed from the balancer. Default:false.backend_tcp_keepalive(duration string, optional): Timeout for sending TCP keepalive probes to backend connections. Set to0sto disable. Default:5s.
A Redis-protocol aware proxy using connection-level multiplexing (connection pinning). Each frontend connection is exclusively paired with a backend connection for its entire duration. This architecture supports all Redis features, including transactions, blocking commands (BLPOP, etc.), and PubSub.
proxy "redis" "my_redis_proxy" {
source = backends_processor.simple_filter.redis_master
addresses = [":6379"]
preconnect = 5
idle_timeout = "10m"
healthcheck = true
}source(string, required): The ID of the backend provider (inventory or processor).addresses(list of strings, required): List of TCP addresses to listen on (e.g.,[":6379"]).connect_timeout(duration string, optional): Timeout for establishing a new connection to a backend. Default:5s.close_timeout(duration string, optional): Grace period for existing connections to finish after a shutdown signal. Default:30s.backend_wait_timeout(duration string, optional): How long to wait for a backend to become available if the backend pool is empty before returning an error to the client. Default:0s.buffer_size(number or string, optional): Size of the read/write buffers for network I/O. Supports human-readable suffixes likekb,mb,gb(e.g.,"16kb"). Default:16384.max_reused_buffer_size(number or string, optional): Maximum capacity of a buffer that can be returned to the pool for reuse. Buffers larger than this will be dropped to save memory. Supports human-readable suffixes. Default:65536.preconnect(number, optional): The number of connections to establish to backends at startup. Default:0.idle_timeout(duration string, optional): How long an unused connection remains in the pool before being closed. Default:5m.idle_cleanup_period(duration string, optional): The interval at which the proxy checks for and closes idle backend connections that have exceeded theidle_timeout. Default:10s.healthcheck(boolean, optional): Iftrue, the proxy sends aPINGto verify a connection's health before handing it to a client. Default:false.healthcheck_timeout(duration, optional): Timeout for the healthcheck operation. Default:1s.reset_timeout(duration string, optional): Timeout for theRESEToperation performed when returning a connection to the pool. Default:2s.backend_tcp_keepalive(duration string, optional): Timeout for sending TCP keepalive probes to backend connections. Set to0sto disable. Default:5s.log_backend_updates(boolean, optional): If true, logs an INFO message when a backend is added or removed. Default:false.close_on_backend_removal(boolean, optional): Iftrue, client connections are closed if the backend they are connected to is removed from the proxy. Default:false.
Note: When a client disconnects, the proxy automatically sends a RESET command to the backend to clear the connection state (e.g., clearing PubSub subscriptions or discarding open transactions) before returning the connection to the pool.
Warning
The Memcache proxy is currently experimental and may undergo breaking changes in its configuration or behavior. It is not yet recommended for production use.
A Memcache-protocol aware proxy supporting both ASCII and Meta protocols. It uses Ketama consistent hashing to route keys to backends.
proxy "memcache" "my_memcache_proxy" {
source = backends_inventory.static.memcache_nodes
addresses = [":11211"]
flush_backend_when_added = false
}source(string, required): The ID of the backend provider (inventory or processor).addresses(list of strings, required): List of TCP addresses to listen on (e.g.,[":11211"]).connect_timeout(duration string, optional): Timeout for establishing a new connection to a backend. Default:0s.close_timeout(duration string, optional): Grace period for closing connections during shutdown. Default:0s.buffer_size(number or string, optional): Size of the read/write buffers for network I/O. Supports human-readable suffixes likekb,mb,gb(e.g.,"16kb"). Default:16384.client_queue_size(number, optional): The maximum number of pipelined requests allowed per client connection. Default:64.backend_input_queue_size(number, optional): Size of the internal buffer for requests waiting to be sent to a backend connection. Default:1024.backend_inflight_queue_size(number, optional): Size of the internal buffer for tracking requests that are currently being processed by a backend. Default:512.backend_min_connections(number, optional): The minimum number of persistent connections to maintain for each discovered backend. Default:1.backend_max_connections(number, optional): The maximum number of persistent connections allowed per backend. Default:backend_min_connections.backend_tcp_keepalive(duration string, optional): Timeout for sending TCP keepalive probes to backend connections. Set to0sto disable. Default:5s.max_fields_per_command(number, optional): The maximum number of space-separated fields allowed in a single Memcache command line. Default:16.flush_backend_when_added(boolean, optional): Iftrue, MLB will send aflush_allcommand to a backend immediately after it is discovered. Useful for ensuring a clean state when adding new cache nodes. Default:false.log_backend_updates(boolean, optional): If true, logs an INFO message when a backend is added or removed. Default:false.