Often in projects, there is a need to perform deferred tasks, such as sending email, push, and other specific tasks specific to the domain area of your application. The difficulties begin when the usual crontab is no longer enough, when batch processing is not suitable, and when each task unit has its own execution time or it is assigned dynamically.

To solve this problem, a solution called  Trigger Hook was created. The schematic diagram of the operation is shown in Figure 1. The diagram shows what happens to tasks during their entire life cycle. Changing the color means changing the status of the task.

  • Red task — d task whose launch time is not yet soon
  • Yellow task — a task whose launch time is coming soon
  • Green task — a task whose launch time has come
  • Blue task — a task that was processed
  • Grey — not confirmed the status of the task in the database
  • Black — command to delete

Life cycle tasks:

  • When creating a task, it gets into the database (square block) (red and yellow).
  • Tasks are loaded into memory (triangular block) if their start time is coming soon (red->yellow). This structure is implemented in the form of a prioritized queue (heap).
  • When the task execution time comes, it is sent for execution (yellow->green). An intermediate buffer is used before processing to compensate for peak loads.
  • If the task is successfully submitted, it is deleted from the database (green->blue). An intermediate buffer is used before deletion, also to compensate for peak loads.

#go #kubernetes #symfony #microservice

Deferred Tasks in A Microservice Architecture
1.90 GEEK