How to work with pull and push methods?
Asynchronous data processing #
When a request involves some resource-intensive operations, you should consider performing these operations asynchronously, without forcing the user to wait for them to finish.
There are two methods for asynchronous data processing: pull and push.
In the pull method, whenever a request includes some complex operations, you create a task and save it to permanent storage, such as a database. Then in a separate process (such as the cron job) you get this task and process it.
This method is easy to implement, but it has some drawbacks. For example, tasks must be periodically taken from their place of storage. If you do this too rarely, tasks will be processed with a long delay, and if too often, this will create large overheads.
In the push method, you can use message queues (for example, RabbitMQ, ActiveMQ, Amazon SQS, etc.) to manage tasks. Whenever a new task enters the queue, it initiates the processing of this task by the handler.