Keycloak Ops
Isometric dark navy platform with glowing pink database cylinders and cubes linked by dashed lines, suggesting server resources for a Keycloak deployment
sizing

Keycloak Resource Requirements: CPU, RAM, Disk, Database

Size Keycloak RAM and CPU by workload, check PostgreSQL support and disk I/O, and use a Docker Compose example with memory limits for an Intel N100.

By Keycloak Ops Editorial · ·Updated · 6 min read

For a small production Keycloak deployment, start with a 2 GB memory limit per container and a supported database such as PostgreSQL. Size CPU by the rate of password logins, token refreshes and client credential grants. The worked example below shows how far 2 vCPU goes with headroom. Keycloak container guide, Keycloak sizing guide.

Keycloak resource requirements at a glance

Resource Documented figure In the examples
Container memory limit 2 GB for smaller production deployments. A limit of at least 750 MB approximates the former 512 MB heap cap. mem_limit: 2g
Baseline RAM per pod 1250 MB, including realm caches and 10,000 cached sessions Under the 2 GB limit
Heap and non-heap Maximum heap is 70% of the container memory limit. Non-heap memory is about 300 MB. Default heap settings
CPU, password logins 1 vCPU per 15 logins per second 12 per second with a 2 vCPU budget for logins alone
CPU, refresh and client credentials 1 vCPU per 120 requests per second, for each type 96 per second with a 2 vCPU budget for either request type alone
CPU headroom 150% extra for spikes in the load No cpus: cap
Java (non-container install) OpenJDK 25 for the ZIP distribution Uses the Keycloak container image
Database Keycloak supports PostgreSQL 14.x through 18.x and lists 18 as tested postgres:17-alpine
Database load For multi-AZ Aurora PostgreSQL, 1400 write IOPS and 0.35 to 0.7 vCPU per 100 login, logout or refresh requests per second No IOPS limit set
Instance count Two or more in a typical production environment One Keycloak service

The documented figures come from the Keycloak sizing guide, container guide, OpenJDK guide, database guide and production guide.

Keycloak used AWS c7g.2xlarge instances and an Aurora PostgreSQL database with 1,000,000 users and 20,000 clients for its reference tests. Use the figures as a starting point and load-test your own workload before deploying. Keycloak sizing guide.

Which Java version does a non-container install need?

Install OpenJDK 25 for the Keycloak ZIP distribution. Keycloak OpenJDK guide.

How much RAM does Keycloak need?

Set a 2 GB limit per Keycloak container for a smaller production deployment. The image bases the maximum and initial JVM heap sizes on the container limit, using -XX:MaxRAMPercentage=70 and -XX:InitialRAMPercentage=50. Use JAVA_OPTS_KC_HEAP to override the heap settings. Keycloak container guide.

The single-cluster sizing example uses 1250 MB of base memory, including realm caches and 10,000 cached sessions. It subtracts non-heap memory before dividing by the maximum heap fraction to get the container limit. Keycloak sizing guide.

memory limit = (1250 MB base - 300 MB non-heap) / 0.7 ≈ 1360 MB

In Keycloak’s multi-cluster reference test, user and client sessions stayed in the database without in-memory caching. The guide says single-site setups cache a fixed number of those sessions. Keycloak sizing guide.

For heap tuning, cache caps and metrics, see Keycloak memory usage and heap sizing.

How much CPU does Keycloak need?

Budget 1 vCPU for every 15 password logins per second. For refresh token requests and client credential grants, budget 1 vCPU per 120 requests per second for each type. Keycloak recommends 150% extra CPU capacity for spikes, startup and failover. Keycloak sizing guide.

Here’s the arithmetic for a 2 vCPU budget when all requests are of one type. For mixed traffic, add the CPU estimates for each request type before applying headroom, as in Keycloak’s single-cluster calculation. Keycloak sizing guide.

2 vCPU / (1 + 150%) = 0.8 vCPU of load
0.8 vCPU x 15 password logins per second = 12 password logins per second
0.8 vCPU x 120 refresh or client credential requests per second = 96 per second

Keycloak’s reference test used Argon2 with 5 hash iterations and a minimum memory size of 7 MiB. In those tests, AWS c7i and c7a cores handled up to twice as many client credential or refresh operations as c7g cores. Password hashing throughput per core stayed steady across those instances. Keycloak sizing guide.

Save the following as Dockerfile next to compose.yml. Building with kc.sh build lets the container start with start --optimized and skip the build at startup. This example pins Keycloak 26.8.2. Keycloak container guide, Keycloak 26.8.2 release.

FROM quay.io/keycloak/keycloak:26.8.2 AS builder
ENV KC_HEALTH_ENABLED=true
ENV KC_DB=postgres
RUN /opt/keycloak/bin/kc.sh build

FROM quay.io/keycloak/keycloak:26.8.2
COPY --from=builder /opt/keycloak/ /opt/keycloak/
ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]

What does Keycloak need from the database?

Use a supported external database for production. Keycloak lists PostgreSQL 14.x through 18.x as supported and 18 as tested. The bundled dev-file database is for development. The default maximum connection pool size is 100, set by db-pool-max-size. Keycloak database guide.

Keycloak loads persistent user sessions from the database into embedded caches as needed. The in-memory session caches default to 10,000 entries per node. Keycloak caching guide.

For multi-AZ Aurora PostgreSQL, Keycloak’s guide budgets 1400 write IOPS and 0.35 to 0.7 vCPU per 100 login, logout or refresh requests per second. Use the IOPS figure when sizing database storage for that workload. Keycloak sizing guide.

N100 specifications against the documented limits

Intel lists 4 cores, 4 threads and a 16 GB maximum memory capacity for the N100. On a machine with 16 GB installed, subtract the two Compose limits to estimate the room left for the host and other services. Intel N-Series comparison chart.

16 GB installed - 2 GB Keycloak - 1 GB PostgreSQL = 13 GB remaining

A compose file with the limits set

Save this example as compose.yml and place PG_PASS and KC_ADMIN_PASS in a project .env file. Compose uses ${VAR:?error} to stop when a required value is unset or empty. With build: ., Compose looks for Dockerfile in the directory containing compose.yml. Compose environment variables guide, interpolation reference, build reference.

This example assumes a reverse proxy on the host terminates TLS. When using xforwarded, configure the proxy to overwrite the X-Forwarded-* headers. Keycloak reverse proxy guide.

services:
  postgres:
    image: docker.io/library/postgres:17-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: keycloak
      POSTGRES_USER: keycloak
      POSTGRES_PASSWORD: ${PG_PASS:?set PG_PASS in .env}
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    mem_limit: 1g
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U keycloak -d keycloak"]
      interval: 30s
      retries: 5

  keycloak:
    build: .
    image: local/keycloak:26.8.2
    command: start --optimized
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      KC_DB_URL_HOST: postgres
      KC_DB_URL_DATABASE: keycloak
      KC_DB_USERNAME: keycloak
      KC_DB_PASSWORD: ${PG_PASS}
      KC_HOSTNAME: https://auth.example.com
      KC_HTTP_ENABLED: "true"
      KC_PROXY_HEADERS: xforwarded
      KC_BOOTSTRAP_ADMIN_USERNAME: admin
      KC_BOOTSTRAP_ADMIN_PASSWORD: ${KC_ADMIN_PASS:?set KC_ADMIN_PASS in .env}
    ports:
      - "127.0.0.1:8080:8080"
    mem_limit: 2g
    healthcheck:
      test: ["CMD", "bash", "-c", "{ printf 'HEAD /health/ready HTTP/1.0\\r\\n\\r\\n' >&0; grep 'HTTP/1.0 200'; } 0<>/dev/tcp/localhost/9000"]
      interval: 30s
      retries: 5
      start_period: 90s

The KC_ variables are documented in Keycloak’s configuration reference. Use the PostgreSQL image reference for the POSTGRES_ variables, the 17-alpine tag and the data mount at /var/lib/postgresql/data. The pg_isready probe checks whether PostgreSQL accepts connections. PostgreSQL 17 documentation.

The Compose file sets mem_limit: 2g for Keycloak and mem_limit: 1g for PostgreSQL, with no cpus cap. Keycloak’s sizing guide reports a performance drop when its pods were throttled. Compose Container specification, Keycloak sizing guide.

Compose waits for PostgreSQL to pass its health check before starting Keycloak because depends_on uses service_healthy. The Compose Workload specification also documents healthcheck fields test, interval, retries and start_period, plus the CMD-SHELL and CMD forms. For restart: unless-stopped, see the Compose services reference.

The Keycloak check uses Bash and /dev/tcp to query /health/ready on the default management port, 9000. The port stays unpublished in this example. Keycloak health guide.

For proxy troubleshooting, see Keycloak hostname and proxy errors.

When does one box stop being enough?

Run two or more Keycloak instances if users need to keep signing in after one instance goes down. Keycloak clustering uses JGroups and Infinispan. Keycloak production guide.

Keycloak’s single-cluster example sizes for 45 logins, 360 client credential grants and 360 refresh requests per second. Across three pods, each pod requests 3 vCPU, has a 7.5 vCPU limit and a 1360 MB memory limit. The database calculation also includes 5 logouts per second. It suggests Aurora db.t4g.large (2 vCPU) or db.t4g.xlarge (4 vCPU), depending on acceptable response times at peak load. Keycloak sizing guide.

That sizing example uses the documented 1250 MB baseline with cached sessions. Keycloak’s separate multi-cluster test kept user and client sessions in the database without the in-memory session cache. Keycloak sizing guide.

To compare other options, see Keycloak vs authentik vs Authelia.

FAQ

Can Keycloak run with 1 GB of RAM?

A 1 GB host has less memory than the 2 GB limit Keycloak recommends for a small production container. At a container limit of 1 GiB, the default 70% maximum heap works out to about 717 MiB. Keycloak container guide.

How many users can Keycloak handle on one server?

There is no fixed user count in Keycloak’s sizing method. Estimate demand from password logins, refresh requests and client credential grants per second. Keycloak’s reference database held 1,000,000 users and 20,000 clients. Its CPU guidance starts at 1 vCPU per 15 password logins per second. Keycloak sizing guide.

The sizing figures come from Keycloak’s AWS reference setup. The server guidance follows the documentation for release 26.8.2 as of November 22, 2026. The adapted Dockerfile and Compose example were not run. Keycloak documentation.

Sources

  1. Keycloak: Concepts for sizing CPU and memory resources
  2. Keycloak: Running Keycloak in a container
  3. Keycloak: Configuring the database
  4. Keycloak: Configuring Keycloak for production
  5. Keycloak: Configuring distributed caches
  6. Keycloak: Tracking instance status with health checks
  7. Keycloak: Configuring a reverse proxy
  8. Keycloak: All configuration
  9. Keycloak: Getting started with OpenJDK
  10. Keycloak 26.8.2 release
  11. Keycloak 26.8.2 documentation
  12. Intel N-Series Processor comparison chart
  13. Docker Official Image: postgres
  14. PostgreSQL 17 documentation for pg_isready
  15. Docker Docs: Compose services reference
  16. Docker Compose Container specification
  17. Docker Compose Workload specification
  18. Docker Docs: Compose Build Specification
  19. Docker Docs: Compose interpolation
  20. Docker Docs: Set, use, and manage variables in a Compose file with interpolation

Related