Slow GraphQL Query with Custom JWT Auth and only two records without relationships

We have been looking in to the GraphQL API as an alternative to what we currently use. However, there are some strange performance issues which don’t seem to make sense.

Our test setup is fairly simple:

Custom JWT Authentication which populates token.sub in to user.data.tokenId
One collection: Users
Two Rules:

  1. readAll when: when the %%user.data.tokenId matches the users.tokenId field
  2. default denyAllAccess
    One index: user.tokenId

There are only two records in the users collection at the moment and the query is only returning a single attribute which is about 32 chars.

The results we are seeing are that the query consistently takes about 1.5-3 seconds round trip.

To produce an auth error before the query runs, and get an idea of latency due to global location - we removed the jwtTokenString from the request header which drops the request time down to ~70ms

Any ideas?

We think we’ve found our issue, based off another few posts here, we took a look at the app service hosting location vs the cluster.

As we set up our initial cluster as global in a shared GCP service, the chosen region was not compatible with the regions available in the available AppServices GCP regions. So a different global region was chosent and we thing that may have something to do with the latency.

We’ll investigate further as time permits.

Hi @AzC, welcome to the community.

That’s correct. It is generally recommended that your App Service’s region is the same as your Database Deployment’s region to mitigate the impact of latency caused due to inter-region data transfer. This is considered as a Local Deployment.

Sure, please let us know if you find any other bottlenecks.

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB