User search sometimes does not return newly created users

Problem statement

We are running automated tests that involve creating a user and then trying to find that user by calling this user search endpoint: /api/v2/users?q=.

We have noticed that occasionally nothing is found even though a user was just created with the email we are searching for.

Cause

As mentioned in our public docs, the GET /api/v2/users endpoint is eventually consistent. This means that search results may not reflect a recently completed write operation. However, if the request is repeated after some period of time, the response will eventually return up-to-date data.

Solution

Based on this use case (searching using an email address), if you need immediate and consistent results, we would recommend using the Management API’s Get Users By Email endpoint.