<?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: Alif Akbar</title>
    <description>The latest articles on DEV Community by Alif Akbar (@alifakbxr).</description>
    <link>https://dev.to/alifakbxr</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3256187%2F1ca8c3dd-a18f-4945-aa81-448c965b059e.jpeg</url>
      <title>DEV Community: Alif Akbar</title>
      <link>https://dev.to/alifakbxr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alifakbxr"/>
    <language>en</language>
    <item>
      <title>Agentic Commerce: What Happens When an AI Agent Actually Places an Order?</title>
      <dc:creator>Alif Akbar</dc:creator>
      <pubDate>Fri, 23 Oct 2026 04:48:43 +0000</pubDate>
      <link>https://dev.to/alifakbxr/agentic-commerce-what-happens-when-an-ai-agent-actually-places-an-order-f9n</link>
      <guid>https://dev.to/alifakbxr/agentic-commerce-what-happens-when-an-ai-agent-actually-places-an-order-f9n</guid>
      <description>&lt;p&gt;AI agents are getting better at understanding what users want, comparing options, and interacting with external tools. But commerce introduces a different level of complexity.&lt;/p&gt;

&lt;p&gt;Finding the right product is one thing. Making sure the transaction actually succeeds is another.&lt;/p&gt;

&lt;p&gt;Imagine an AI agent that can search multiple stores, compare prices, check inventory, and initiate checkout. What happens when the price changes between selection and payment? What if the payment succeeds but the merchant never confirms the order? Or what if the agent retries and accidentally creates a duplicate order?&lt;/p&gt;

&lt;p&gt;These are not just AI reasoning problems. They are transaction reliability problems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where things get complicated
&lt;/h3&gt;

&lt;p&gt;A few scenarios seem particularly important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stale inventory:&lt;/strong&gt; A product is available when the agent checks, but goes out of stock before checkout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Price changes:&lt;/strong&gt; The final price differs from the price the user approved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ambiguous outcomes:&lt;/strong&gt; A checkout request times out, leaving the agent unsure whether an order was created.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate actions:&lt;/strong&gt; Retrying a failed request creates multiple orders.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Incomplete handoffs:&lt;/strong&gt; The agent initiates a purchase, but the actual order confirmation arrives later or never arrives.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User authorization:&lt;/strong&gt; The agent exceeds its budget or completes a purchase without sufficiently clear approval.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tool connectivity alone does not necessarily solve these problems. Even if an agent can communicate with a merchant through an API or MCP server, the underlying transaction can still fail in unexpected ways.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does agentic commerce need a separate transaction layer?
&lt;/h3&gt;

&lt;p&gt;One possible approach is to treat purchasing as an explicit state machine rather than a single tool call.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DISCOVERED → SELECTED → AWAITING_APPROVAL → CHECKOUT_PENDING → ORDER_CONFIRMED&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Failure and uncertainty would need their own states, such as &lt;code&gt;PAYMENT_FAILED&lt;/code&gt;, &lt;code&gt;OUTCOME_UNKNOWN&lt;/code&gt;, or &lt;code&gt;CANCELLED&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The distinction between an action being requested and an order being confirmed is especially important. A successful API response does not always mean a completed purchase.&lt;/p&gt;

&lt;p&gt;Idempotency, reconciliation, explicit authorization, and reliable status updates could become just as important as the agent's ability to reason about products.&lt;/p&gt;

&lt;p&gt;Of course, some of these concerns already exist in conventional e-commerce systems. The interesting question is how they should be handled when an autonomous agent becomes the client coordinating multiple services.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few questions for developers
&lt;/h3&gt;

&lt;p&gt;I'm curious how others see this evolving:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Should agentic commerce rely primarily on existing payment and e-commerce infrastructure, or does it need a dedicated transaction orchestration layer?&lt;/li&gt;
&lt;li&gt;Where should transaction state live: inside the agent, the merchant integration, or a separate service?&lt;/li&gt;
&lt;li&gt;How should agents recover from ambiguous outcomes without creating duplicate purchases?&lt;/li&gt;
&lt;li&gt;Should MCP servers expose higher-level commerce operations, or should they remain thin interfaces over existing APIs?&lt;/li&gt;
&lt;li&gt;What level of human approval should be mandatory before an agent commits a real transaction?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Agentic commerce is often discussed in terms of better recommendations and smoother checkout experiences. But I suspect transaction reliability and trust will be just as important.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's the biggest technical challenge you think agentic commerce needs to solve before people can confidently let AI agents make purchases on their behalf?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>mcp</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How I Eliminated Race Conditions in a High-Concurrency Ticketing API</title>
      <dc:creator>Alif Akbar</dc:creator>
      <pubDate>Sun, 21 Jun 2026 15:09:48 +0000</pubDate>
      <link>https://dev.to/alifakbxr/how-i-eliminated-race-conditions-in-a-high-concurrency-ticketing-api-21ek</link>
      <guid>https://dev.to/alifakbxr/how-i-eliminated-race-conditions-in-a-high-concurrency-ticketing-api-21ek</guid>
      <description>&lt;p&gt;Executive Summary: To eliminate race conditions in a high-concurrency ticketing system, I implemented PostgreSQL's FOR UPDATE clause for row-level database locking alongside Go worker channels for in-memory queue serialization. This approach completely prevents inventory over-selling by guaranteeing singular data mutation execution even under flash-sale load.&lt;/p&gt;

&lt;p&gt;If you have ever built an application that handles live event ticketing, flash sales, or limited-inventory drops, you know the dread of burst traffic. The primary engineering challenge isn't just scaling the servers—it's maintaining absolute data integrity when a thousand users attempt to mutate the exact same database row at the exact same millisecond.&lt;/p&gt;

&lt;p&gt;Without strict concurrency controls, you get race conditions. Two users buy the last ticket, the database processes both reads before either write is committed, and suddenly, you have an over-sold event and an angry client. Here is how I solved this problem using Go (Golang) and PostgreSQL.&lt;/p&gt;

&lt;p&gt;Why Go?&lt;br&gt;
I chose Go for its concurrency model. Goroutines are incredibly cheap compared to traditional OS threads, allowing the API to multiplex thousands of incoming HTTP requests across a small number of threads. Coupled with the Gin framework, the routing layer easily sustains massive RPS (Requests Per Second) without eating up RAM.&lt;/p&gt;

&lt;p&gt;The Database Bottleneck&lt;br&gt;
Building high-concurrency systems requires more than just picking a fast language; it demands careful design across the entire stack (database, application, and cache). When dealing with valuable inventory data, naive optimism leads to data corruption. The key to eliminating race conditions isn't preventing concurrent requests, but rather serializing them at the exact right bottleneck using strong database guarantees.&lt;/p&gt;

&lt;p&gt;The most valuable lesson here is to delegate transactional integrity to the tools built for it: PostgreSQL. The Go application remains a fast, stateless facilitator, while the database handles the final mutation safeguards. This separation of concerns is ultimately what allowed the API to survive under production pressure.&lt;/p&gt;

&lt;p&gt;The typical naïve approach is an application-level check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// ❌ BAD PATTERN (Race Condition prone)&lt;/span&gt;
&lt;span class="n"&gt;ticket&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FindTicket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ticket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"AVAILABLE"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UpdateTicket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"SOLD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;userID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By the time UpdateTicket executes, another goroutine has likely already read the status as "AVAILABLE".&lt;/p&gt;

&lt;p&gt;The Solution: Row-Level Locking&lt;br&gt;
To fix this, we must push the concurrency control down into the PostgreSQL transaction utilizing the FOR UPDATE clause.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// ✅ SECURE PATTERN&lt;/span&gt;
&lt;span class="n"&gt;tx&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c"&gt;// Lock the specific ticket row until this transaction completes&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ticket&lt;/span&gt; &lt;span class="n"&gt;Ticket&lt;/span&gt;
&lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Raw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SELECT * FROM tickets WHERE id = ? FOR UPDATE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Scan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;ticket&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ticket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s"&gt;"AVAILABLE"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Rollback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ErrTicketAlreadySold&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Mark as sold and commit&lt;/span&gt;
&lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"UPDATE tickets SET status = 'SOLD', user_id = ? WHERE id = ?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;userID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Commit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;SELECT ... FOR UPDATE&lt;/code&gt; instructs PostgreSQL to place an exclusive lock on the fetched row. If 1,000 requests try to execute this simultaneously, PostgreSQL forces them into a queue. The first request locks the row, updates it, and commits. When the second request is finally granted the lock, it reads the updated state, sees the ticket is no longer available, and gracefully rolls back.&lt;/p&gt;

&lt;p&gt;The Result&lt;br&gt;
This architecture guarantees 100% data integrity with zero double-bookings, even under extreme load. The trade-off is database contention, but because the transaction is so fast (reading and updating a single indexed row), the lock duration is measured in microseconds.&lt;/p&gt;

&lt;p&gt;Check this &lt;a href="https://alifakbar.pw/en/blog" rel="noopener noreferrer"&gt;Alif akbar BLOG&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>postgres</category>
      <category>architecture</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
