How it works
- Instagram tells loop about each new comment (webhook — An HTTP request that another service sends to your server when something happens, for example "a payment succeeded".).
- If the comment matches a rule, loop writes a “send this DM” job into a database table.
- Workers take jobs from that table, send the DM, and reply “Sent you a DM 📩” under the comment.
Design choices
- The database table is the queue (outbox pattern — Write the job to a database table first, then let workers send it. A crash does not lose the job: the workers continue from the table.). If a server crashes, the jobs
are still in the table, and the workers continue where they stopped. Two workers never take the
same job (
FOR UPDATE SKIP LOCKED). - Time limits on every step: 30 seconds for a whole job, 10 for the DM, 8 for the public reply.
- The API description comes first. The dashboard is generated from it, and works with a fake server while the real one is off.