This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
Mechanism for prevent api race conditions in queue #694
savchukoleksii
started this conversation in
General
Replies: 1 comment 2 replies
-
@osiset
1. Are this store shared between workers processes? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
Queue with multiple workers that process many jobs that works with Shopify API (or other) must deal with API Race Conditions.
For example:
Laravel Horizon started with 1000 workers, we dispatch many jobs that works with Shopify API into queue and also related to 1 API key (for example, 500 jobs). Horizon will process jobs in parallel without prevention only 1 job running per 1 shop.
Desired behavior to keep 1 job in the same time per API key or multiple, but without exceeding Shopify Rate Limitter. Also to prevent long running processes that freezes in API retries.
Solutions
Keep 1 worker per shop - This is very bad idea, because we dont know how many tenants will use our app as also it vary fast will exceed server memory.
Limit queue to process only 1 job per API key. This better solution, but currently Laravel does not have solution for this.
Possible solution, but it need review and improvement
The idea of this solution is using Laravel
Redis::funnel
for prevent many jobs work with Shopify API, but in this case we can not define how many attemps and retries job execute. To come over this problem we can use Laravel featureretryUntil
in job.Example solution:
Job:
So, we will keep only 1 running job per API Key, but in this case all jobs must be atomic and not depends on each other, because during retries they can be reordered.
Open for discussions
Beta Was this translation helpful? Give feedback.
All reactions