Common Patterns
Scheduler - Queue - Worker (SQW)
-
EventBridge Rule invokes scheduler
-
Scheduler reads records from database
-
Scheduler sends records to SQS queue
-
Worker lambdas are automatically spun up to read records off the queue
-
Worker lambdas do stuff
Pros:
-
Easy to setup and understand
-
Easy concurrency with lambda
Cons:
-
Scheduler can hit lambda timeout for large jobs
Paginating SQW
-
EventBridge Rule invokes scheduler
-
Scheduler reads one page from database
-
Scheduler sends records from that page to the worker queue
-
If there are more pages available, the scheduler sends a message to the scheduler queue with the last key read from the database
-
The scheduler reads that message from the scheduler queue, and starts reading from the database where the previous invocation left off
-
Once there are no more records from the database, the scheduler does not send another record to the scheduler queue, and it stops running
-
While the scheduler is paging through the database, the worker lambdas are reading from the worker queue and doing stuff
Pros:
-
Easy concurrency with lambda
-
Scheduler will not hit the lambda timeout
Cons:
-
A little more complicated to setup and understand