Repository navigation
Replies: 9 comments 17 replies
|
For the |
|
Another alternative is to remove the caching layer: #46496 I strongly believe a stateless application is the way to go. No clustering, no extra exposed ports, no latency to worry about, and support single cluster, multi-az, multi-region, and multi-planet. The only cache that has some use is the Note that Hibernate 2LC is available for user to inject their preferred caching solution. |
|
Perspective as a beginner: I spent days already just wrestling with weird situations where, for example, changes to token mappers and such would see no effect until I change some completely random value (in my case, I set and unset Direct access grants). This is really painful. I can only suspect that caching is the reason for this, and I've seen other slightly-related questions on SO and such where people do, and then undo, random things to get things working. I agree that @pruivo that stateless first is the way to go. |
|
Apologies in advance if I misunderstand anything, I’m still relatively new to this area and am learning as I go, so I hope my comments are taken in the constructive spirit intended. I completely agree with @pruivo ’s proposal to remove the cache layer entirely. After watching the recording ( https://youtu.be/rHeOQejcCQI?t=231 ) and reviewing the recent community survey results ( https://www.keycloak.org/2026/03/distribution-surver-results ) , it seems clear that the Keycloak cache layer or the caching approach, has become a source of complexity, operational challenges, and division within the community. Given the technical benefits @pruivo mentioned, along with the opportunity to simplify the architecture and create greater alignment across the community, the proposal feels very compelling to me. As a CNCF project, shouldn’t Keycloak also strive to align as closely as possible with true cloud-native principles? |
Hypothesis 1: Disable caching of persistent sessions is OKRationale: We want to see if we can simplify a Keycloak setup with fewer or no caches. This input will provide us data for the session caches. We’ll run different experiments for different caches to track the effects on response times and CPU usage. While we could come up with synthetic test cases, we would like to see numbers from real production environments and possible challenges. TL;DR: Disable the session cache and post your results in this thread In a multi-cluster setup of Keycloak, this is already disabled by default, so we already have some numbers on this one. Feel free to share your results in private by sending it to the email address listed in the profile of @ahus1. Expected outcome
Prerequisites
Cache size default10k entries * number of pods Extra expected Database usage when cache is disabled
SELECTs are usually faster than any INSERT/UPDATE, so the additional load should only add some percentages to the CPU load of the database. If running this, make sure your database CPU usage is not over 60% already on average usage. Test first in a test environment. AssumptionIf the number of active sessions in the access token lifetime is larger than the cache sizes, your session cache is probably not very effective currently anyway. How to disable the cachePersistent sessions enabled (default) + QuestionsFor your production or test environment, read the values before/after with comparable load:
Link to guides |
Hypothesis 2: Disable caching of users is OKRationale: We want to see if we can simplify a Keycloak setup with fewer or no caches to eventually become stateless. This input will provide us data for the session caches. We’ll run different experiments for different caches to track the effects on response times and CPU usage. While we can come up with synthetic test cases, we would like to see numbers from real production environments and possible challenges. TL;DR: Disable the user cache and post your results in this thread Feel free to share your results in private by sending it to the email address listed in the profile of @ahus1. Expected outcome
Prerequisites
Cache size default10k entries on each Keycloak node Extra Database usage when cache is disabled
SELECTs are usually faster than any INSERT/UPDATE, so the additional load should only add some percentages to the CPU load of the database. If running this, make sure your database CPU usage is not over 60% already on average usage. Test first in a test environment. AssumptionUsers are cached only per node. If a second request touches a different node then it doesn’t benefit from the cache entries from the first request, so your caches might not be very effective currently anyway. How to disable the user cache
QuestionsFor your production or test environment, read the values before/after with comparable load:
Link to guides |
|
Thank you @ahus1 for opening this discussion and inviting community feedback. We ran Keycloak v22 with a self-hosted external Infinispan cluster on AWS serverless infrastructure (Fargate) and eventually had to move away from it. The core issue: JGroups requires stable node identities and direct inter-container communication , neither of which ephemeral/serverless containers reliably provide. Node failures during routine maintenance caused Infinispan members to drop and rejoin unpredictably, leading to split-brain scenarios and disrupted session state. Beyond serverless, this affects any team with modern deployment practices like rolling deployments, OS patches, CVE cycles all cycle containers, and every restart is a membership change that triggers rebalancing and risks a partition window. The operational burden of self-hosting Infinispan, combined with the 'run the engine' overhead ultimately led us to move away and implement a Managed Redis-based solution as alternative for external infinispan. We fully support Hypothesis (Keycloak setup with fewer or no caches and using Persistent Store). For teams already running HA PostgreSQL (RDS/Aurora), the database is the natural authority for durable state. Removing a second distributed cluster that has to stay consistent with it simplifies the failure model — a stateless Keycloak backed by PostgreSQL seems the right direction. What about the other cache types?Sessions are a great first step, but a truly stateless Keycloak means addressing everything currently in Infinispan — authenticationSessions, loginFailures, actionTokens, work, and the local caches (realms, users, authorization, keys, crl). Has Keycloak core team done any feasibility study for migrating all of these to the persistent store? On latency and L1/L2 cachingWe understand that pushing everything to PostgreSQL could introduce latency under high concur 10000 rency. Has the team done any performance testing here? We're also curious whether an L1/L2 model has been previously considered:
For teams who want no managed cache dependency, even a simple L1 Cache + PostgreSQL two-tier model would be a significant improvement over the current setup. Three independent Redis/Valkey implementations — worth paying attention toThree separate teams, without coordination, built Redis/Valkey cache providers for Keycloak:
Three teams, different orgs, same root cause, same solution. That's a strong signal. A first-class path to persistent store — optionally with L1/L2 — would consolidate this rather than leaving scattered implementation across separate repos. Open Questions
These baselines would also help teams as they plan and prepare for performance testing to determine the destination state for Keycloak caching. We're happy to contribute performance testing for the persistent store solution with L1/L2 — and please do let us know if Keycloak or Red Hat has already executed benchmark testing with this configuration so we can use those as a baseline. Thanks for driving this forward @ahus1 it's the architectural direction that would benefit lot of enterprise teams and the community !! |
|
FYI, I've created a SPIKE this morning: #49469 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
In Keycloak, “caches” are used for different things:
This is quite a mix of functionality. While it was sometimes difficult to set things up with older versions, the most recent versions should be a lot more simple to set up and upgrade.
This post summarizes what we have done in the past, what we think the current state is, and where we want to head in the future. Please comment on this discussion to provide ideas and also context in which setups this works well or where it needs improvements.
How we made them simpler to use
We evolved the area of caching in the past based on user feedback:
Working for the vast majority of users?
To gather some information from the Keycloak repository: We have not seen many open issue around Infinispan lately
We plan to continue to improve it, but it would require some specific information about a user’s setups, performance analysis, etc. We would appreciate it if people would engage in GitHub issues to provide context and data about the problems they are experiencing. We’ll be happy to dive into details with you.
How caching should evolve
What currently is the field of “caching” in Keycloak, is actually a mix of different functionalities. It can be split-up and changed depending on different architecture decisions on the overall Keycloak project.
Here’s some of the ongoing work and alternatives that already exist:
There is also the experimental feature “clusterless” which allows storing the user sessions only in the external Infinispan and not in the database.
Looking further into the future:
Changing things one step at a time
So where should we start to change things? Post your comment below to engage in this conversation!
All reactions