<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aslı Kök</title>
    <description>The latest articles on DEV Community by Aslı Kök (@imgeaslikok).</description>
    <link>https://dev.to/imgeaslikok</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3840381%2Fbafd4b07-bf49-46af-9f05-fd083dd19478.jpeg</url>
      <title>DEV Community: Aslı Kök</title>
      <link>https://dev.to/imgeaslikok</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imgeaslikok"/>
    <language>en</language>
    <item>
      <title>The bug between DB commit and queue enqueue</title>
      <dc:creator>Aslı Kök</dc:creator>
      <pubDate>Mon, 23 Mar 2026 15:41:32 +0000</pubDate>
      <link>https://dev.to/imgeaslikok/the-bug-between-db-commit-and-queue-enqueue-idc</link>
      <guid>https://dev.to/imgeaslikok/the-bug-between-db-commit-and-queue-enqueue-idc</guid>
      <description>&lt;p&gt;Hey everyone,&lt;/p&gt;

&lt;p&gt;While working with FastAPI and Celery, I ran into a subtle reliability issue that I think is easy to overlook.&lt;/p&gt;

&lt;p&gt;A very common flow looks like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;db.commit()&lt;br&gt;
celery_task.delay(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;At first glance, this seems perfectly fine.&lt;br&gt;
But there’s a problem: this is not atomic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The hidden bug&lt;/strong&gt;&lt;br&gt;
If your process crashes between these two lines:&lt;/p&gt;

&lt;p&gt;the database transaction is already committed&lt;br&gt;
but the task is never enqueued&lt;/p&gt;

&lt;p&gt;The job is silently lost. No retry. No error. No visibility.&lt;/p&gt;

&lt;p&gt;This makes it especially dangerous in production systems where reliability matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A possible solution: Transactional Outbox&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One approach to solve this is the Transactional Outbox pattern:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write both the state change and an "event" into the database in the same transaction&lt;/li&gt;
&lt;li&gt;Use a separate worker to read and publish those events to the queue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This ensures that nothing is lost, but it comes with trade-offs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;added complexity&lt;/li&gt;
&lt;li&gt;eventual consistency&lt;/li&gt;
&lt;li&gt;extra moving parts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I put together a more detailed write-up here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@imgeaslikok/the-bug-between-db-commit-and-queue-enqueue-c8ef92207863" rel="noopener noreferrer"&gt;https://medium.com/@imgeaslikok/the-bug-between-db-commit-and-queue-enqueue-c8ef92207863&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Curious about real-world approaches&lt;/p&gt;

&lt;p&gt;I’m really interested in how others handle this in production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do you implement outbox/inbox patterns?&lt;/li&gt;
&lt;li&gt;Do you rely on retries and idempotency instead?&lt;/li&gt;
&lt;li&gt;Have you ever run into this issue in real systems?&lt;/li&gt;
&lt;li&gt;Any simpler alternatives that still guarantee delivery?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Would love to hear your experience.&lt;/p&gt;

</description>
      <category>python</category>
      <category>fastapi</category>
      <category>celery</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
