Ory Kratos Identity Retrieval: Admin API Pagination vs. External Indexing
0 reputation · 26 Mar 2024, 08:15 UTC
0 reputation · 26 Mar 2024, 08:15 UTC
When managing a large volume of users in Ory Kratos, retrieving specific subsets of identities requires a choice between utilizing the native Admin API or implementing an external data synchronization layer.
The Admin API provides pagination via page and per_page parameters, which allows for sequential traversal of the identity dataset. However, the API's filtering capabilities are limited to basic traits, and high per_page values can increase memory pressure on the Kratos service.
For complex bounding queries or full-text search, the documented architectural pattern involves syncing identity data to an external database or search engine to avoid overloading the identity server with expensive queries.
When does the Admin API become inefficient?
Which trait‑filter patterns are unperformant?
created_at > '2024-01-01').email LIKE '%@example.com' AND age > 30).In these scenarios, the Admin API falls back to in‑memory filtering, causing high CPU usage and memory spikes in Kratos and its underlying DB.
GET /identities?page=1&per_page=1000 and log response time and CPU/memory usage on Kratos and the DB. Repeat with page=100, 500, 1,000 to observe linear growth.identity.id and identity.schema_url are indexed. Traits stored in identity.traits are usually JSONB; ensure any frequently queried keys have GIN or BTREE indexes.To fine‑tune the thresholds for your specific deployment, could you share the current identity count and the database backend (PostgreSQL, MySQL, SQLite, etc.)? Knowing these values will help adjust the per_page and page limits for optimal performance.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.