<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Concurrency on Laputa</title>
    <link>https://chenjianyong.com/tags/concurrency/</link>
    <description>Recent content in Concurrency on Laputa</description>
    <generator>Hugo</generator>
    <language>en-GB</language>
    <lastBuildDate>Wed, 16 Jul 2025 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://chenjianyong.com/tags/concurrency/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Write Atomicity in MongoDB</title>
      <link>https://chenjianyong.com/blog/2025/write-atomicity-in-mongodb/</link>
      <pubDate>Wed, 16 Jul 2025 00:00:00 +0000</pubDate>
      <guid>https://chenjianyong.com/blog/2025/write-atomicity-in-mongodb/</guid>
      <description>&lt;p&gt;Recently, I’ve been building a task system with the following workflow:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;A user submits a task.&lt;/li&gt;&#xA;&lt;li&gt;The task is immediately stored in MongoDB.&lt;/li&gt;&#xA;&lt;li&gt;The task ID is returned to the user, who can poll for its status.&lt;/li&gt;&#xA;&lt;li&gt;A background worker periodically fetches pending tasks and executes them.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;This model is quite common when task execution can take a long time.&lt;/p&gt;&#xA;&lt;p&gt;However, here’s the catch: the service is deployed across multiple instances, and they may all fetch the same pending tasks from MongoDB. This creates a race condition — a task could be executed multiple times, and the final result becomes unpredictable.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
