I'm looking for some guidance on how to handle multiple backend processes attempting to access the RingCentral api for the same account simultaneously. Each separate process runs independently, on a separate schedule, and has its own token refresh logic built in. For the most part, this all works well. But every once in a while I end up with a token that is "expired". The only way to resolve it is to have the user log back into our app so the token can refresh again.
This happens very infrequently, but often enough that it's an annoyance both to me and to the customers impacted. But it's infrequent enough that it's hard to track down the issue. I am suspicious that my two separate processes are colliding with each other, getting fired off at the same time, and the refreshed token in one process overrides the refreshed token in the other one, and the system ends up with an invalid token at the end. Is that a possibility?
What is the best way to handle this scenario?
Just a little background - the two processes run continuously, on separate schedules, and check the user's account for new data. One process runs every 5 minutes, and the other process runs every 2 minutes.