Why Keycloak logins slow down and how to find the cause first
When users report slow or failing sign-ins, the first job is to find out where the time goes: inside Keycloak, in its database, in an LDAP or identity provider call, or in the reverse proxy in front of it. Guessing at the cause wastes time and often leads teams to resize the wrong component. Start by enabling metrics. Keycloak exposes Prometheus-format metrics at /metrics on its management interface when it is started with --metrics-enabled=true, and the observability guide describes optional HTTP request and cache histograms that add detail on request latency and cache behavior. Confirm in your own environment that the management interface is reachable only from your monitoring network, because it should not sit on the public hostname.
Read the metrics in the order that narrows the search. Check whether request duration rises for all endpoints or only for the login and token paths, whether error counts rise with it, and whether the cache and database pool signals move at the same time. A slowdown that appears on every request points toward the JVM, the database or the proxy. A slowdown limited to one federation path points toward the LDAP or brokered identity provider. The exact metric names and labels depend on the Keycloak version you run, so confirm them against the observability guide for your release before you build dashboards or alerts on them.
Bring in outside help when the metrics show a pattern you cannot explain after checking your own database, directory and proxy, or when the slowdown affects production logins and your team lacks someone who can read thread dumps and Java Flight Recorder recordings with confidence. Ask any partner to state in writing which evidence they will collect first, how they will protect user data in dumps and recordings, and how they will hand back the findings. Keycloak runs in your infrastructure, so the work should be planned around your change windows and access rules.
Which Keycloak metrics to check first during a slow login incident
During a slow login incident, read a small set of signal groups in a fixed order: request timing and errors first, then the layers beneath them. Each group is only meaningful against a baseline captured while logins were healthy, so record those values before you need them.
HTTP request timing and errors
Start with request duration and error counts on the public frontend. A rise in latency with flat error counts points to slow processing, while a rise in 5xx responses points to failing dependencies or an overloaded node. Compare current percentiles with the baseline for the same hour of day, since login traffic follows business patterns. HTTP request histograms are optional and only produce data once they are enabled, so confirm they are on before the incident, or you will have no request-level timing to compare.
Metrics guideDatabase connection pool use
Watch how many connections are in use against the configured maximum and how long requests wait for one. A pool that stays near its ceiling during login spikes usually means slow queries or long transactions are holding connections, not that the pool is too small. Compare active connections and wait behavior with the baseline. If the pool is healthy while logins are slow, the bottleneck is likely outside the database driver, so move on to the database server itself.
Cache activity and hit ratios
Keycloak keeps realm, user and session data in caches, and their metrics show whether logins read from memory or go back to the database. A falling hit ratio after a restart, a realm change or a node leaving the cluster means more database work per login. Look for steady growth in cache entries and evictions. Cache histograms are optional, so enable them ahead of time if you need this signal during an incident.
JVM memory and garbage collection
Check heap use after collections and the time spent in garbage collection. Heap that climbs and never settles, or collection pauses that grow across the incident window, can stall request threads even when the database is idle. Compare heap and pause times with the baseline and with the time of the last deployment or configuration change. A single pause is rarely the cause, but a steady increase in pause time usually is.
Thread state counts
Track the number of live threads and how many are blocked, waiting or runnable. A growing count of threads waiting on the same lock or a connection pool suggests contention, and that group is what you bring to a thread dump. Compare counts with the baseline, because a higher thread count is normal under load. Treat a thread count that keeps rising after load drops as a sign that work is not completing.
Metrics endpoint exposure
Metrics are served at /metrics on the management interface only when the server starts with --metrics-enabled=true. Confirm that the scrape target, the management port and any network policy allow your monitoring system to reach it, and that the public frontend does not expose it. Keep the metrics scrape running continuously so the baseline exists. A metrics gap during the incident is itself a finding to record.
Where a slow login spends its time across Keycloak, the database, LDAP and the proxy
A login starts in the user's browser, passes through the reverse proxy to a Keycloak node, and then fans out to the database, an LDAP or Active Directory federation provider, and an upstream identity provider. Keycloak emits Prometheus metrics on its management interface at /metrics when metrics are enabled, so start there. Hops outside Keycloak, such as proxy latency, database query time and directory response time, need measurement on their own side. Check each hop in turn before blaming Keycloak.
Login hops, showing which ones Keycloak metrics cover and which need proxy, database or directory measurement.
Which diagnostic tool fits which symptom
This table compares metrics, thread dumps, Java Flight Recorder recordings, database-side query views and proxy access logs against the symptoms teams see most often in slow or failing logins. Start with the row that matches your symptom, then check the access and overhead columns before enabling anything on a production node. The main takeaway is that metrics and proxy logs answer where a problem sits, while thread dumps and JFR explain what the JVM was doing.
| Tool | Symptom it fits | Data it gives | Overhead or access needed | Usually run by |
|---|---|---|---|---|
| Prometheus metrics at /metrics | Steady high login latency or a gradual climb in error rates across the cluster | Request rates and durations when HTTP metrics are enabled, cache and JVM figures, trends over time | Needs --metrics-enabled=true and access to the management interface; measure the effect of optional histograms in a non-production environment first | Platform or SRE team with the monitoring stack |
| JVM thread dumps | Stuck requests where logins hang and nothing errors, or a node that stops responding under load | A snapshot of every thread's state and stack, showing threads blocked on locks, pools or network calls | Shell access to the pod or host with the JDK tools; a single dump is brief, but repeated dumps should be planned around customer traffic | Application or platform engineers with JVM experience |
| Java Flight Recorder recordings | Intermittent latency spikes, garbage collection pauses or slow requests that come and go | Time-stamped JVM events over a chosen window, including GC, allocation, socket and lock activity | Needs a recording started with a chosen profile and retrieved from the node; measure overhead in a non-production environment before using it in production | Performance engineers or senior Java engineers |
| Database-side query views | Slow logins that only appear when the database is busy, or pool waits that point to queries | Active sessions, long-running statements, lock waits and connection counts from the database engine | Requires read access to database monitoring views, which the database team usually controls; confirm the permissions your DBA will grant | Database administrators |
| Reverse proxy access logs | Failing logins for one realm or one client, or errors that appear only through a specific hostname or path | Status codes, upstream response times, request paths and hostnames as seen at the edge | Needs access to proxy logs and correlation with Keycloak logs; log retention and sensitive fields should be confirmed with your security team | Network, ingress or platform team |
| Keycloak server logs at debug level | Failing logins for one realm where the cause is a configuration or federation error | Realm-specific events, authentication errors and federation or brokering messages when the category is raised | Raising log levels adds volume and can expose sensitive data; limit the change to the category and time needed | Keycloak administrators |
How to read thread dumps and JFR recordings without guessing
Start with several thread dumps taken a short interval apart during a slow period, not a single snapshot. One dump shows what threads were doing at one instant, which is easy to misread. Three or four dumps, a few seconds to a minute apart, show which threads stay in the same place. Capture them with the JDK tools available in your Keycloak container or host, such as jstack, and record the time of each dump so you can line it up with metrics and logs from the same window. Then look for three patterns. Threads waiting to acquire a database connection point to pool exhaustion, which you can confirm against the connection pool metrics. Many threads waiting on the same monitor or lock point to contention inside Keycloak or a shared cache. Threads parked in socket reads to an LDAP directory or a brokered identity provider point to slow external calls, which is a problem outside Keycloak even though users see a slow login.
A Java Flight Recorder (JFR) recording adds detail a thread dump cannot give: how long each lock was held, allocation pressure, garbage collection pauses and how time was spent across methods over a window. Use it when the dumps show contention but not its cause, or when slowness comes and goes too quickly to catch in dumps. Confirm with your Keycloak version and JDK which JFR options are available before you plan the capture, and agree a short recording window with the team, since longer recordings grow large and add overhead. Keep the window tied to a known slow period so the file is useful when analyzed.
Treat every JFR recording and thread dump as sensitive data. Recordings can capture request content, parameters and values in memory, and thread dumps can show user identifiers, client identifiers and hostnames. Store them in a restricted location, limit who can read them, set a retention period, and remove copies from shared tickets. Check with your security team whether captures from production require approval before they are taken, and document that approval alongside the incident record.
Separating Keycloak problems from database, LDAP or proxy problems
Keycloak problems usually show up as high heap pressure, long garbage collection pauses, saturated request threads or cache behavior that forces repeated reads. These signals appear in the Prometheus metrics that Keycloak exposes at /metrics when metrics are enabled on the management interface, so check them before touching the server.
- Rising JVM heap and GC time: Heap usage that climbs steadily and collection time that grows with load points to memory pressure inside Keycloak.
- Busy request handling with healthy dependencies: If HTTP request latency rises while database and LDAP calls stay flat, the time is spent inside Keycloak itself.
- Cache miss spikes after restarts or topology changes: Elevated cache misses that settle over time usually indicate warm-up, not a fault.
- Ruled out by: Flat heap and GC curves, normal thread counts and latency that is already high at the proxy before requests reach Keycloak.
- First confirmation step: Compare the JVM and HTTP panels for the same time window as the slow logins, then take a single thread dump from the running process to see where request threads are waiting.
If the JVM panels are flat during the slowdown, move to the other layers before changing Keycloak settings.
The database is a frequent source of slow logins because every session, token and event write depends on it. Keycloak's supported production databases include PostgreSQL (14 to 18), MariaDB, MySQL, Microsoft SQL Server, Oracle Database and Azure SQL, and the signals differ mainly in how the connection pool and query waits behave.
- Connection pool exhaustion: Requests that wait for a connection while database latency stays low suggest the pool is too small or connections are held too long.
- Slow queries and lock waits: Long query times or lock contention in the database engine's own statistics point to the database, not Keycloak.
- Database CPU, IOPS or replication lag: Saturated storage or a lagging replica during the incident is strong evidence for the database layer.
- Ruled out by: Low pool wait times, normal query latency and healthy database host metrics during the slow period.
- First confirmation step: Read the database engine's active session and slow query views for the incident window, and compare pool metrics in Keycloak with those numbers. Do not change pool sizes until you have that comparison.
Keycloak's database configuration guide is the reference for supported engines and settings.
When Keycloak federates users from LDAP or Active Directory, a slow directory adds latency to every login that touches a federated user. Keycloak documents LDAP and Active Directory user federation, so the directory path is part of the login chain and needs its own checks.
- Latency only for federated users: Local accounts log in normally while federated accounts stall, which points to the directory or the connection to it.
- Timeouts in directory calls: Connection or search timeouts recorded in Keycloak logs at the relevant category level indicate the directory or network path is slow.
- Large search scopes or missing indexes: Broad searches that return many entries slow down user lookup and synchronization.
- Ruled out by: Fast logins for local users, quick directory responses from a test client run from the Keycloak host and normal Keycloak thread behavior.
- First confirmation step: Run a read-only search from the Keycloak host with the same bind account and base DN, and time it against the directory server. This does not change production.
If the directory answers quickly from the Keycloak host but logins are still slow, return to the JVM and proxy tabs.
The reverse proxy or load balancer sits in front of every request, so it can add delay, drop connections or send traffic to unhealthy nodes. Keycloak's production guidance expects TLS everywhere and a reverse proxy with path restrictions, which means the proxy configuration is part of the login path.
- Gaps between proxy and Keycloak timings: If the proxy records much higher request times than Keycloak reports, the delay is in the proxy, the network between them or TLS negotiation.
- Upstream errors or resets: Proxy logs showing 502 or 504 responses, or connection resets to specific nodes, point to a node or proxy timeout problem.
- Uneven load across nodes: One node receiving most traffic or failing health checks shows a balancing or stickiness issue.
- Ruled out by: Matching timings at the proxy and in Keycloak, and no upstream errors during the incident.
- First confirmation step: Compare proxy access logs with Keycloak HTTP metrics for the same requests, and check whether the proxy's upstream timeouts are shorter than the slowest login flows.
Confirm the proxy's timeout and header settings with your proxy vendor's documentation, since those values vary by product and version.
Set up metrics and capture a baseline before the next incident
This sequence turns on Keycloak's Prometheus metrics, checks that they are reachable only from inside your network, and records what normal login performance looks like. With a baseline and an agreed capture runbook, your team can compare an incident against known numbers and collect thread dumps and recordings without improvising.
Enable the metrics endpoint
The platform engineer starts Keycloak with
--metrics-enabled=truein the same configuration used for production, either as a command-line flag or the equivalent entry in your configuration file. Restart the node and confirm the endpoint exists by requesting/metricson the management interface from a host inside your network. The check passes when the response is plain text in Prometheus format and includes Keycloak metric names. If nothing answers, confirm the management port your version uses and that the flag reached the running process, not only the file on disk.Confirm metrics stay off public hostnames
The security engineer requests
/metricsthrough the public frontend hostname and through the reverse proxy that serves it. The check passes when the public path returns a not-found or denied response and the metrics only answer on the management interface. Review the proxy path rules alongside Keycloak's production guidance on separating the admin and public hostnames, because a proxy rule that forwards the whole management context can expose internal series such as client identifiers and cache sizes. Record the test result in the change ticket.Choose histograms and cache metrics deliberately
The platform engineer and the service owner decide whether to enable the optional HTTP request histograms and cache histograms that Keycloak's observability guide describes. Histograms give latency distributions per request type, which is what you need to see slow logins, but each one adds series that Prometheus must store. Write the decision down with the reason, and list the dashboards and alerts that depend on it. The check is a written configuration record that another engineer can read and reproduce on a second node.
Scrape the endpoint with your Prometheus
The monitoring engineer adds a scrape job for every Keycloak node in your existing Prometheus, using the management address and a network path that does not cross the public proxy. Confirm each target shows as up in the Prometheus targets view, then run a query for a basic Keycloak metric and confirm values change between two requests a few minutes apart. Set a label for environment and node so that per-node behavior stays visible during a cluster incident. If a node is missing, check the network policy and the port before changing Keycloak.
Record a baseline under normal load
During a normal business period, the monitoring engineer saves query results for login request rate, request latency percentiles, error responses, database connection pool usage and JVM memory and garbage collection for each node. Store these as a dated snapshot or export the dashboard panels, and note the traffic pattern at the time, such as peak sign-in hours or a batch job. The check is a snapshot that a reader can compare against an incident window. Ask your team which periods count as normal, because a baseline captured during a quiet holiday will mislead later comparisons.
Agree the incident capture runbook
The incident commander, platform lead and security owner write a short runbook that names who may take thread dumps and Java Flight Recorder recordings, which node to target first and how to avoid restarting a node that users still depend on. It should also state where recordings and dumps are stored, who can access them because they can contain sensitive data, and how long they are kept under your retention rules. The check is a signed-off document stored where on-call engineers can find it during an outage, with a named owner for each step.
Rehearse the capture in a non-production environment
The on-call team runs the runbook against a non-production Keycloak with a similar configuration and realistic test traffic from your load testing tools. They take a thread dump, start and stop a recording, and confirm the files reach the agreed storage location and open in the tools your engineers use. Record how long each action took and where people got stuck. The check is a rehearsal log with any gaps fixed in the runbook. Confirm with your vendor or platform team the exact recording options supported by your Java runtime version before the rehearsal.
Protecting metrics, thread dumps and recordings in production
Metrics, thread dumps and flight recordings are the fastest way to find a slow login, and each one also reveals data about your users and your runtime. The cards below cover the controls that keep diagnostics useful without widening the attack surface, from endpoint separation to change control on a live cluster.
Metrics endpoint on the public path
The /metrics endpoint is served on the management interface when --metrics-enabled=true is set, but a reverse proxy that forwards every path to Keycloak can still expose it to the internet. Check that the proxy blocks /metrics, the health paths and the admin console and Administration REST API from public hosts. Test this from outside your network, not from inside the cluster, because internal tests will pass even when public access is open.
Tokens and user data in captures
Thread dumps and Java Flight Recorder files can contain request parameters, usernames, client IDs and fragments of query strings that appear in active stack frames or buffers. Treat every capture as sensitive personal data and as potentially containing credentials. Ask your security team to classify captures in the same tier as application logs that hold user identifiers, and confirm who can read them before anyone requests one.
Access to the Java process
Taking a thread dump or starting a recording requires access to the running JVM, usually through the container runtime, a shell on the host or a JMX-capable tool. Limit this to a named group of on-call engineers, use a separate account rather than shared administrator credentials, and log each session. Confirm whether your platform exposes JMX or remote debugging ports, and close any that are not needed for diagnosis.
Retention and transfer of captures
Captures often leave the cluster when engineers attach them to tickets or send them to a vendor. Define where captures may be stored, how long they are kept and how they are encrypted in transit and at rest. Delete captures once the incident is closed unless a documented reason keeps them, and avoid email or chat as a transfer channel. Confirm these rules with your data protection owner before the first incident, not during it.
Change control for diagnostics on a live cluster
Enabling metrics histograms, raising log levels or starting a recording changes runtime behavior and can add overhead during the incident you are trying to resolve. Record each change with its owner, reason, start time and rollback step, and apply it through the same deployment path as other configuration where possible. Agree in advance which diagnostics may be enabled without a change window and which need approval, so responders are not making that decision under pressure.
Metrics guideSeparating admin and management paths
Keycloak's production guidance calls for exposing the admin console and Administration REST API on a different hostname or context path from public frontend URLs. Apply the same separation to diagnostics: operators should reach metrics and management endpoints through a private network, VPN or bastion, while end users only see the login and account paths. Review this separation after each upgrade, since a new route or path can bypass a rule written for an older layout.
Keycloak production guideQuestions teams ask before they bring in outside help
What does an outside Keycloak performance review cost?
No price list is published, and a quote follows from a written scope. Most engagements are fixed-scope, so the scope, deliverables and timeline are agreed in writing before work starts. The main cost drivers are the size of the deployment (number of nodes, realms and clients), the number of federation links to LDAP, Active Directory or upstream identity providers, and how much access the reviewer needs to the database, the reverse proxy and directory teams. Ask for the quote to separate one-time diagnosis from any recurring retainer for upgrades or continuous testing, and to state what evidence the reviewer needs from you before work begins.
How long does a first Keycloak performance diagnosis take?
The duration depends mostly on whether the slowdown can be reproduced on demand. A problem that appears during a known login peak can be captured with metrics, thread dumps and a Java Flight Recorder recording in a single window. An intermittent slowdown may need several capture windows spread over days, because the reviewer has to catch the state while it is happening. Ask the provider to state in the quote how many capture windows are assumed, what happens if the problem does not reproduce during them, and who is responsible for scheduling those windows.
What does the work need from our team?
The reviewer needs read access to Prometheus metrics exposed on the management interface, the Keycloak logs for the same period, and the ability to take thread dumps and JFR recordings on the nodes under review. A test window matters because some captures add load or need a controlled login workload. Expect to name contacts for the database, the reverse proxy or load balancer, and any LDAP or identity provider the realms depend on, since many slow logins are caused outside Keycloak. Ask the provider to list these requests in the written scope so your teams can plan the access before the work starts.
Can our own team diagnose Keycloak slowdowns without a partner?
Often yes, if the team has the skills to read JVM and database signals and a baseline to compare against. The first checks are usually the same ones a partner would run: request latency and error rates from metrics, database connection pool waits, cache behavior, and whether the slowdown starts at Keycloak or upstream. An outside review adds the most value when the cause sits across boundaries, such as a database pool that is saturated by a directory lookup, or a proxy that queues requests. Be honest about who on your team can take and interpret a thread dump or a JFR recording under production constraints.
Why does baseline metrics matter for a performance review?
Baseline metrics show what normal login latency, throughput and database behavior look like before the problem started, so the reviewer can tell a regression from a deployment that was always slow. Without a baseline, the first part of the work becomes building one, which adds time and makes the findings harder to prove. If you have not enabled metrics, ask whether the provider will enable them in a controlled way first and how long you should collect data before the captures. Metrics are exposed at the management endpoint when metrics are enabled, so confirm that step with your platform team early.
What does a fixed-scope performance engagement deliver?
A fixed-scope engagement usually delivers a written diagnosis of the observed slowdown, the evidence behind each finding (metrics extracts, thread dump analysis, JFR observations), a list of likely causes separated into Keycloak, database, directory and proxy areas, and recommended changes with their owners. Ask whether the scope includes a retest after fixes are applied and whether the deliverable names which findings are confirmed and which still need evidence. DeployOpen does not issue audit reports or attestations, so the output is engineering evidence for your team, not a compliance certificate.
Does an outside review change our production configuration?
It should not do so without a written change plan approved by your team. The safer pattern is to agree in the scope which changes are recommended, which the reviewer may apply in a test environment, and which need your change control process. Captures such as thread dumps and JFR recordings are generally read-only on the running process, but they still consume resources, so they belong in an agreed window. Ask the provider to confirm exactly which actions it takes on production nodes and who approves each one.
Limits and what to confirm in your environment
Most slow-login investigations stall on facts the team has not written down: which Keycloak build runs, which database version sits behind it, and what the Java runtime allows. The cards below list the checks to make before reading metrics, dumps or recordings, so the findings apply to the system you actually operate.
Keycloak version and distribution
Start by confirming whether you run the upstream Keycloak project or the Red Hat build of Keycloak, and the exact version of each. The current upstream release is 26.8.1, published October 13, 2026, while Red Hat build versions follow their own schedule, so the version on Red Hat's product page may not match your container image. Metric names, histogram options and default behavior change between minor releases, so write down the exact image tag before you compare a dump or a dashboard against published guidance.
Keycloak docsDatabase versions and replication
Record the database engine and version, and confirm it is on the supported list in the Keycloak database guide. For PostgreSQL, the supported range is 14 to 18. In a clustered design, confirm with your database team that the database is synchronously replicated, because both supported high availability designs depend on it. Asynchronous replicas can change where slow queries appear and how failover looks in your traces.
Database guideMetrics and histogram options
Confirm that metrics are enabled with --metrics-enabled=true and that you can reach /metrics on the management interface. HTTP request and cache histograms are optional, so check whether your version and configuration expose them before you build latency panels. Without histograms, you can see counts and averages but not the tail latency that causes failed logins under load.
JFR and Java runtime access
Java Flight Recorder and thread dumps need a JDK that includes the tooling, and a container image that lets you run jcmd or jfr inside the process. Confirm the JVM vendor and version, whether the image is a slim runtime without diagnostic tools, and whether your security policy allows writing recordings to a persistent volume. Decide these before an incident, not during one.
Proxy timeouts and logs
A reverse proxy or load balancer can close connections, buffer responses or return 502 and 504 errors while Keycloak is still working. Record the proxy's upstream, read and idle timeouts, and where its access and error logs go. Compare proxy timing with Keycloak request timing before you change Keycloak settings, because a short proxy timeout can look like a slow identity provider.
Managed or operator-based restrictions
If you run Keycloak through the Keycloak Operator, a managed Kubernetes service, or a vendor appliance, confirm who can exec into the pod, attach a debugger, or change JVM flags. Operator-managed pods are often replaced on upgrade, which discards manual changes, and some managed platforms block signal-based thread dumps. Agree on the diagnostic path with the platform owner and record it in the runbook.
How DeployOpen scopes and delivers Keycloak performance work
DeployOpen approaches slow or failing Keycloak logins as a scoped investigation of the running system in your infrastructure. We start from the evidence your team already collects, then add metrics, thread dumps and Java Flight Recorder captures where they answer a specific question, and we separate Keycloak problems from database, LDAP and proxy problems before recommending a fix.
How we scope
- Engagements are fixed-scope, with the systems, Keycloak versions, realms and login paths in question agreed in writing before work starts.
- We confirm whether metrics at /metrics are enabled, which management port and proxy sit in front of Keycloak, and where database and LDAP logs can be read.
- The written scope names the symptoms, time windows and evidence each finding must rest on, so the quote follows from what is actually examined.
How we build
- We walk the metrics first: HTTP request timing, database connection pool and cache signals, then compare them with the login failures users report.
- We capture thread dumps and JFR recordings under agreed conditions in your environment, and record exactly when and how each capture was taken.
- We test each suspected cause against the other tiers, such as database latency, LDAP response time and proxy timeouts, before attributing the slowdown to Keycloak.
How we hand over
- You receive a written findings report that ties each finding to the metric, dump or recording that supports it, with reproduction steps.
- Recommended configuration and tuning changes come with the settings to change, the expected effect to watch for, and the rollback path.
- Your team receives the queries, dashboard panels and capture procedures used, so the same investigation can be repeated on your own schedule.
How we support
- After handover we can retest the affected login paths to confirm that the changes removed the slowdown or failure.
- Ongoing support, upgrades and continuous testing are available as retainers, which can cover Keycloak version upgrades that change performance behavior.
- Retainer scope, response expectations and review cadence are written into the agreement, so you know what support covers before you rely on it.

