# Horizontal Scaling
Since simple-auth uses signed cookies to manage the session, horizontal scaling is easy. Simply running more than one instance side-by-side leads to easy scaling.
WARNING
To most effectively scale, we recommend using postgresql or mysql/mariadb. You can read more about using different databases here
You need to make sure simple-auth is behind some sort of load balancer. This example uses traefik, but nginx or swarm balancing should work fine.
# docker-compose
Creating replicas is as simple as adding this in the service:
deploy:
replicas: 4
Full docker-compose.yml
version: '3.3'
services:
# Traefik listening on port 88 (in case 80 conflicts with something...)
traefik:
image: traefik:v2.3
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:88"
ports:
- "88:88"
- "8090:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
simpleauth:
image: zix99/simple-auth:latest
environment:
SA_WEB_LOGIN_COOKIE_JWT_SIGNINGKEY: a-unqiue-signing-key # REPLACE THIS WITH SOMETHING UNIQUE!!!!
SA_DB_DRIVER: postgres
SA_DB_URL: "host=db user=postgres dbname=postgres password=test sslmode=disable"
depends_on:
- db
#region replicas
deploy:
replicas: 4
#endregion replicas
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.simpleauth.rule=Host(`auth.${DOMAIN}`)" # Fill in with your own domain
- "traefik.http.routers.simpleauth.entrypoints=web"
db:
image: postgres:13-alpine
environment:
POSTGRES_PASSWORD: test
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata: {}