8

Our application makes use of a service account that has been authorized for the entire domain by the admin. With this service account our application accesses the domain user's emails with Gmail APIs like GetMessage.

All of a sudden, starting this week, we have started receiving the errors intermittently

Quota exceeded for quota metric 'Queries' and limit 'Queries per minute per user' of service 'gmail.googleapis.com' for consumer 'project_number:XYZ

There is no change in our application or frequency at which we access emails. We are using batch size of 10 while using the API.

The 'Quota exceeded errors count (10 sec) - Queries per minute' graph in the GCP dashboard is empty. So we are really not sure what is going on and why we are suddenly hitting the quota limits.

Also, I am not sure how the 'per-user' limit is applied when my app accesses the user mailboxes with the service account. The documentation around this is vague, at least to me.

These errors are really impacting our ability to serve our customers. Moreover not knowing why we are getting these errors is shaking our confidence in the Gmail APIs.

Any help in this regard is highly appreciated.

Thanks

UPDATE: Today we are seeing lots of

"User-rate limit exceeded.  Retry after <timestamp>"

errors. Seems like this time around we are hitting some quota limit other than 'queries per minute'. While I look in my client implementation and figure out why this is happening, feel free to share any recommendations you may have.

Thanks.

Urjit
  • 375
  • 1
  • 3
  • 12
  • Batching wont help your quota you need to slow down your going to fast. per user limit is applied by IP address. Your service account is a single user. – Linda Lawton - DaImTo Jul 09 '20 at 13:26
  • Can you share the relevant parts of the code you're working on? Have you considered using techniques like Exponential Backoff? – Iamblichus Jul 09 '20 at 14:33
  • The exact same error also appeared to us yesterday, I think for the first time, but we're also tweaking our front-end code in this days so I'm not sure if it's that. – Alberto T. Jul 11 '20 at 10:29
  • 2
    @DaImTo So, the 'per-user' limits will apply to my service account treating it to be a single user? Or are the 'per-user' limits applied to the target mailbox that I am trying to access with my service account? Also, my code runs in the cloud, and so the external IP seen by Google could be the same. Could that be a problem? How to get around it? The idea behind using a service account is to be able to serve the entire domain which could have hundreds of email accounts. But if the quota is going to be applied consider single user/ip for my client app it will be a problem. – Urjit Jul 13 '20 at 11:45
  • @Iamblichus our client-side code does have exponential back off and that is why certain retries succeed. However, the client-side code hasn't changed in months, and yet all of a sudden we are seeing these errors. Its as if all of a sudden the client has started to run faster resulting in more queries per min, which doesn't make any sense. – Urjit Jul 13 '20 at 11:50
  • AFAIK when a Service Account is impersonating other accounts, the queries don't affect the SA quota, but the impersonated account quota. It could be useful to see the code you're using, in order to find out what's going on here. – Iamblichus Jul 13 '20 at 14:03
  • @Urjit Per-user quotas are always enforced by the Gmail API, and the user's identity is determined from the access token passed in the request. There is no way around that. – Linda Lawton - DaImTo Jul 13 '20 at 16:17
  • Thank you @Iamblichus and DalmTo for confirming my understanding that the quota being applied does nohe SA quota, but the end user quota. So, its always possible that even if your application is not really going over the quota, the user could have subscribed to some other service that might be eating into the quota, correct? Is there a way around this? Does google make any effort to ensure one application/service does not consume all the quota and starve any other application/service that is trying to access the mailbox? – Urjit Jul 14 '20 at 05:48
  • Did you find a solution? – xaphod Sep 26 '21 at 18:26
  • I have the same issue: 'Quota Exceeded'. In the Gmail API dashboard for me it states there is a per-user query limit of 15000 per minute, or 250 per second. Based on `https://stackoverflow.com/questions/377454/how-do-i-get-my-program-to-sleep-for-50-milliseconds` I added `from time import sleep` then `sleep (0.4)` and I am sending queries in batches of 99, which equates to ~247-248/sec, but I am still hitting the limit. Maybe tuning it down might improve it. – skeetastax Aug 24 '23 at 23:38

1 Answers1

-1

Google analytics has limits and quotas on API requests. You can increase it. If you don't want to do it, daily quotas are refreshed at midnight Pacific Standard Time.

Dmytro
  • 1