<?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: Taocarts跨境</title>
    <description>The latest articles on DEV Community by Taocarts跨境 (@taocarts).</description>
    <link>https://dev.to/taocarts</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%2F3858579%2F102440a9-3cce-4de4-a53b-bba363fcbff1.png</url>
      <title>DEV Community: Taocarts跨境</title>
      <link>https://dev.to/taocarts</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/taocarts"/>
    <language>en</language>
    <item>
      <title>Implementing Soft Deletes and a Retention Policy for Cross-Border Order Records</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Mon, 23 Nov 2026 01:27:17 +0000</pubDate>
      <link>https://dev.to/taocarts/implementing-soft-deletes-and-a-retention-policy-for-cross-border-order-records-2kid</link>
      <guid>https://dev.to/taocarts/implementing-soft-deletes-and-a-retention-policy-for-cross-border-order-records-2kid</guid>
      <description>&lt;h1&gt;
  
  
  Implementing Soft Deletes and a Retention Policy for Cross-Border Order Records
&lt;/h1&gt;

&lt;p&gt;Deleting an order row feels clean. In a cross-border storefront it is usually a mistake.&lt;/p&gt;

&lt;p&gt;We learned this the hard way at Taocarts, the platform behind a reverse-shopping storefront that lets overseas buyers source goods from Chinese marketplaces. Orders here pass through many hands, and a row that disappears from the table takes its whole story with it. Sooner or later someone asks a question you can no longer answer — a refund dispute, a financial review, or a simple "where did this parcel go" ticket from months back.&lt;/p&gt;

&lt;p&gt;So we moved to soft deletes plus an explicit retention policy. This is a short write-up of why, and the parts that were not obvious.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a hard delete hurt us
&lt;/h2&gt;

&lt;p&gt;Three concrete failures pushed us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A refund dispute where the buyer claimed an item was never ordered. The deleted row meant we had nothing to point at.&lt;/li&gt;
&lt;li&gt;A reconciliation job that counted revenue from a snapshot taken before deletion, and then could not explain the difference the next day.&lt;/li&gt;
&lt;li&gt;A compliance question about a parcel whose order had been cleaned up by a well-meaning maintenance script.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In each case the data was not sensitive or fraudulent — it was simply gone. In a flow with this many handoffs, "gone" is the worst state, because you cannot even prove what happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Soft delete: keep the row, hide it
&lt;/h2&gt;

&lt;p&gt;The first change was mechanical. We added a &lt;code&gt;deleted_at&lt;/code&gt; column and scoped default queries to exclude soft-deleted rows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;deleted_at&lt;/span&gt; &lt;span class="kt"&gt;DATETIME&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_orders_deleted_at&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="nf"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deleted_at&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;Every model query now filters &lt;code&gt;WHERE deleted_at IS NULL&lt;/code&gt; unless it explicitly asks for archived records. From the buyer-facing app nothing changed — canceled orders still vanish from the list. What changed is that the data is still there when support or finance needs it.&lt;/p&gt;

&lt;p&gt;One subtlety: a soft delete is only useful if you can actually query the archived rows. We built a small internal screen, restricted by role, that lets support search by order number including archived records. Without that, a soft delete is just a hard delete with extra storage cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retention policy: decide how long, and why
&lt;/h2&gt;

&lt;p&gt;Keeping everything forever is not free. Storage grows, backups grow, and data protection rules increasingly expect you not to keep personal data indefinitely. So soft delete needed a sibling: a retention policy.&lt;/p&gt;

&lt;p&gt;We categorized order data into tiers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Active&lt;/strong&gt; (recent 12 months): fully queryable, included in dashboards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Warm&lt;/strong&gt; (12–36 months): hidden from the app, retained for dispute and tax needs, queryable only through the restricted internal screen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cold&lt;/strong&gt; (older than 36 months): personal fields (address, phone) scrubbed, but financial and line-item totals anonymized and kept for aggregate reporting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The scrubbing job runs monthly and is itself audited. It never touches the financial totals — only the personally identifying columns.&lt;/p&gt;

&lt;h2&gt;
  
  
  The migration was the risky part
&lt;/h2&gt;

&lt;p&gt;Backfilling &lt;code&gt;deleted_at&lt;/code&gt; for historical canceled orders had to be done in batches. We wrote a worker that processed a few thousand rows at a time, with a resumable checkpoint, because a long-running migration on the main table would have locked writes during a sale.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"SELECT id FROM orders WHERE deleted_at IS NULL AND status='canceled' LIMIT 5000"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"UPDATE orders SET deleted_at=created_at WHERE id IN :ids"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"ids"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;commit_checkpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The checkpoint mattered: we ran this twice, once in staging and once in production, and interrupted the production run once on purpose to confirm it resumed correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we would do differently
&lt;/h2&gt;

&lt;p&gt;Two things. First, we would have introduced &lt;code&gt;deleted_at&lt;/code&gt; on day one; retrofitting it was the expensive part. Second, we would have written the retention rules down before building the scrubbing job — the engineering was easy, but the decision about what to keep and for how long involved legal, finance, and support, and that took longer than the code.&lt;/p&gt;

&lt;p&gt;Soft deletes plus a retention policy are not glamorous work. But in a flow where a single parcel passes through many hands and might be questioned months later, keeping the record — and knowing exactly how long to keep it — is what lets you sleep during a review.&lt;/p&gt;

&lt;p&gt;Tags: #webdev #programming #database #ecommerce&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>How We Scaled Cross-Border Order Reads With a Read-Replica Setup</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Sun, 22 Nov 2026 01:18:54 +0000</pubDate>
      <link>https://dev.to/taocarts/how-we-scaled-cross-border-order-reads-with-a-read-replica-setup-2n34</link>
      <guid>https://dev.to/taocarts/how-we-scaled-cross-border-order-reads-with-a-read-replica-setup-2n34</guid>
      <description>&lt;h1&gt;
  
  
  How We Scaled Cross-Border Order Reads With a Read-Replica Setup
&lt;/h1&gt;

&lt;p&gt;Our order database was fine for a long time. Then a single Black Friday broke it — not on the write side, but on reads. Checkout was healthy, but buyer-facing pages (order history, tracking, "where is my parcel") got slow enough that support tickets spiked. The paradox was simple: the busier the sale, the more people refreshed their order pages, and the more they refreshed, the slower everything got.&lt;/p&gt;

&lt;p&gt;Taocarts is the cross-border platform behind this stack, and read replicas turned out to be the least invasive fix we could make. Here is what we did and what surprised us.&lt;/p&gt;

&lt;h2&gt;
  
  
  Diagnose before you split
&lt;/h2&gt;

&lt;p&gt;It is tempting to jump straight to "add replicas." We first confirmed the shape of the problem with query metrics, and it mattered.&lt;/p&gt;

&lt;p&gt;Our workload was overwhelmingly read-heavy. Roughly 95% of queries were reads — order lists, tracking nodes, item lookups. Writes (new orders, status changes, inventory decrements) were a small fraction but obviously critical. That ratio is exactly the scenario replicas are good at. If your workload were write-heavy, splitting reads would barely help.&lt;/p&gt;

&lt;p&gt;The slow queries themselves were not even badly written. They were just numerous, and they were all hitting the same primary that was also serving checkout writes. Read contention was the issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  The topology we landed on
&lt;/h2&gt;

&lt;p&gt;One primary handles all writes. Two replicas handle reads. Simple, boring, effective.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Checkout, order creation, and inventory updates go to the primary.&lt;/li&gt;
&lt;li&gt;Buyer-facing reads — order history, tracking pages, product lookups — go to replicas.&lt;/li&gt;
&lt;li&gt;Admin analytics and internal reports go to a dedicated replica so a heavy report cannot slow down customer pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The routing lives in the data access layer, not scattered across controllers. We have a single place that decides "write or read," and a context flag that pins a request to the primary when needed. Scattering replica routing through the codebase is how you end up with subtle bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The consistency trap nobody warns you about
&lt;/h2&gt;

&lt;p&gt;Here is the part that cost us a week.&lt;/p&gt;

&lt;p&gt;A buyer places an order (write to primary) and immediately lands on the order confirmation page (read from replica). Replication lag means the replica does not have the row yet. The page shows "order not found." The buyer panics and places a second order. Now you have a duplicate — and a support ticket.&lt;/p&gt;

&lt;p&gt;We fixed this with a read-after-write rule: any request that just performed a write is pinned to the primary for a short window (we use a few seconds). After that, reads can go back to replicas. Most frameworks let you set a per-request "use primary" flag; that is enough.&lt;/p&gt;

&lt;p&gt;The general lesson: replicas are eventually consistent, and user flows that assume immediate consistency will break. Identify those flows explicitly and route them to the primary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connection pooling and failover
&lt;/h2&gt;

&lt;p&gt;Two practical things:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pool per node, not global.&lt;/strong&gt; We keep separate connection pools for the primary and each replica. A global pool with mixed targets causes headaches when one node is slow — you cannot isolate it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Health checks and automatic failover.&lt;/strong&gt; If a replica lags too far or goes down, the router should skip it. We monitor replica lag and pull a node out of rotation past a threshold. If the primary fails, we do not auto-promote a replica — that is a deliberate manual decision, because a bad auto-promotion is worse than downtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers looked like
&lt;/h2&gt;

&lt;p&gt;After the split, buyer-facing page p95 latency dropped by more than half during peak, and checkout stayed flat because it no longer competed with hundreds of tracking refreshes. Support tickets about "slow pages" essentially disappeared.&lt;/p&gt;

&lt;p&gt;We also learned to watch replica lag as a first-class metric. It is the number that quietly determines whether your users see fresh data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons worth keeping
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Split reads only after confirming the workload is read-heavy. Measure first.&lt;/li&gt;
&lt;li&gt;Route reads in one place, with a clear "primary" override for read-after-write flows.&lt;/li&gt;
&lt;li&gt;Treat replication lag as a product problem, not just an infra metric — stale data confuses users.&lt;/li&gt;
&lt;li&gt;Pool connections per node so one slow replica does not poison the rest.&lt;/li&gt;
&lt;li&gt;Keep failover deliberate. Automatic promotion is a decision, not a default.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read replicas are not glamorous. But they are the kind of unglamorous plumbing that lets a checkout survive its busiest hour without falling over.&lt;/p&gt;

&lt;p&gt;Tags: #webdev #programming #ecommerce #database&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Rate-Limiting Our Cross-Border Checkout API With a Token Bucket</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Sat, 21 Nov 2026 01:19:04 +0000</pubDate>
      <link>https://dev.to/taocarts/rate-limiting-our-cross-border-checkout-api-with-a-token-bucket-47o7</link>
      <guid>https://dev.to/taocarts/rate-limiting-our-cross-border-checkout-api-with-a-token-bucket-47o7</guid>
      <description>&lt;h1&gt;
  
  
  Rate-Limiting Our Cross-Border Checkout API With a Token Bucket
&lt;/h1&gt;

&lt;p&gt;Black Friday taught us an expensive lesson. Our checkout endpoint, which normally hums along, got hammered by a mix of real buyers and retry scripts. Some of those retries were our own fault — a client that re-posted on a timeout — and each one triggered a fresh round of inventory checks and payment intent calls. We needed a limiter that could tell a burst from an abuse. Taocarts is the platform behind this checkout, and this is how we tuned its front door.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a fixed window was not enough
&lt;/h2&gt;

&lt;p&gt;Our first attempt was the obvious one: a fixed counter per user, reset every minute. It was easy, and it was wrong in two ways.&lt;/p&gt;

&lt;p&gt;First, fixed windows have an edge problem. A client can send N requests at the end of one window and N more at the start of the next — 2N in a few seconds, right at the boundary. Second, a hard cap of N per minute punishes legitimate bursts. A buyer refreshing the page a dozen times while comparing shipping options is not an attacker.&lt;/p&gt;

&lt;p&gt;What we wanted was: allow short bursts, but keep the average rate under control. That is exactly what a token bucket gives you.&lt;/p&gt;

&lt;h2&gt;
  
  
  The model
&lt;/h2&gt;

&lt;p&gt;Picture a bucket per key (we use tenant id plus endpoint). The bucket holds tokens, up to a capacity C. Every request consumes one token. Tokens refill continuously at rate R per second.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A burst is fine as long as the bucket has tokens — that is what capacity C buys you.&lt;/li&gt;
&lt;li&gt;Sustained abuse drains the bucket faster than R refills it, and requests start getting rejected.&lt;/li&gt;
&lt;li&gt;After the abuse stops, the bucket refills and normal traffic resumes without a manual reset.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two parameters do all the work: capacity C controls how big a burst we tolerate; refill rate R controls the long-term average.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation sketch
&lt;/h2&gt;

&lt;p&gt;We run Redis, so the bucket lives there. The clever part is that we do not run a background timer to refill tokens. We compute lazily: when a request arrives, we work out how many tokens would have accrued since the last request, based on elapsed time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;allow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;refill_rate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hmget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"tokens"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"last"&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;tokens&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;

    &lt;span class="n"&gt;elapsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;elapsed&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;refill_rate&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;tokens&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"last"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;

    &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"last"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is lazy refill: no cron, no per-bucket thread. The bucket only "exists" when someone touches it, and stale buckets cost nothing beyond a hash key that we let expire via TTL.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that mattered: atomicity
&lt;/h2&gt;

&lt;p&gt;The naive version above has a race. Two concurrent requests can both read the same token count and both decide they are allowed. Under load, that doubles your effective rate.&lt;/p&gt;

&lt;p&gt;We fixed it with a Lua script executed inside Redis. Reading the hash, computing refill, decrementing, and writing back all happen in one atomic operation on the Redis single thread. No locks on the application side, no distributed coordination — just one script that runs to completion.&lt;/p&gt;

&lt;p&gt;This was not optional. Under normal traffic the race is rare; under a flash sale it is constant. A limiter that leaks under the exact load it is meant to handle is worse than no limiter, because you trust it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers looked like
&lt;/h2&gt;

&lt;p&gt;We set capacity to 20 and refill to 0.5 tokens per second — roughly 30 requests per minute sustained, with room for a 20-request burst. Before the limiter, a single misbehaving client could push several hundred checkout calls a minute and drag down response latency for everyone. After, checkout p99 latency stayed flat during the sale, and the number of duplicate payment intents dropped sharply.&lt;/p&gt;

&lt;p&gt;We also return &lt;code&gt;Retry-After&lt;/code&gt; on rejection, computed from how long until the next token is available. Well-behaved clients back off politely instead of hammering harder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons worth keeping
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fixed windows leak at boundaries; token buckets smooth bursts without punishing them.&lt;/li&gt;
&lt;li&gt;Lazy refill keeps the implementation cheap — no timers, no per-key worker.&lt;/li&gt;
&lt;li&gt;Make the check-and-decrement atomic. Do the race-test under load, not in a unit test.&lt;/li&gt;
&lt;li&gt;Tune capacity and refill separately: one controls bursts, the other controls the average.&lt;/li&gt;
&lt;li&gt;Return &lt;code&gt;Retry-After&lt;/code&gt; so clients cooperate rather than collide.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rate limiting is not glamorous work, but it is the kind of unglamorous plumbing that decides whether checkout survives its busiest hour. We would rather spend an afternoon on a token bucket than an all-nighter on incident calls.&lt;/p&gt;

&lt;p&gt;Tags: #webdev #programming #ecommerce #automation&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Row-Level Security for Multi-Tenant Cross-Border Order Data</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Fri, 20 Nov 2026 01:25:50 +0000</pubDate>
      <link>https://dev.to/taocarts/row-level-security-for-multi-tenant-cross-border-order-data-1bk8</link>
      <guid>https://dev.to/taocarts/row-level-security-for-multi-tenant-cross-border-order-data-1bk8</guid>
      <description>&lt;h1&gt;
  
  
  Row-Level Security for Multi-Tenant Cross-Border Order Data
&lt;/h1&gt;

&lt;p&gt;Our platform serves many independent shop owners. Each one runs a cross-border sourcing operation — customers abroad order from Taobao and 1688, and our system handles purchasing and shipping. Taocarts is the name of that system. Early on, every tenant's data lived behind the same application queries, and we relied on the code to add &lt;code&gt;WHERE tenant_id = ?&lt;/code&gt; everywhere.&lt;/p&gt;

&lt;p&gt;That worked until it didn't. One forgotten clause in a reporting endpoint is all it takes for one shop owner to see another's orders. So we moved tenant isolation from "a convention in the codebase" to "a guarantee in the database." This is a short account of that move and what it cost us.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why application-level checks were not enough
&lt;/h2&gt;

&lt;p&gt;We had dozens of query paths. Most remembered the tenant filter. A few did not — usually the newer, hastily added admin endpoints. Code review catches some, but not all, and the failure mode is severe: cross-tenant data leakage.&lt;/p&gt;

&lt;p&gt;The problem is structural. When isolation lives in application code, correctness depends on every developer, every endpoint, every refactor forever. We wanted a rule that held even if the application forgot.&lt;/p&gt;

&lt;p&gt;PostgreSQL row-level security (RLS) let us put that rule in the database itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting the tenant context per request
&lt;/h2&gt;

&lt;p&gt;The core idea: every request carries a tenant identity, and we set that identity as a session variable before any query runs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="k"&gt;LOCAL&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current_tenant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'tenant_123'&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;SET LOCAL&lt;/code&gt; scopes the value to the current transaction, which matters because our connection pool reuses connections across requests. A plain &lt;code&gt;SET&lt;/code&gt; would leak the value to the next request that borrowed the same connection.&lt;/p&gt;

&lt;p&gt;In our Laravel services, a middleware opens the transaction and sets this variable at the start, and the transaction commits at the end. That gives us a clean boundary: inside the transaction, every query sees the tenant context.&lt;/p&gt;

&lt;h2&gt;
  
  
  The policy itself
&lt;/h2&gt;

&lt;p&gt;On each tenant-scoped table, we enable RLS and add a policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="no"&gt;ENABLE&lt;/span&gt; &lt;span class="k"&gt;ROW&lt;/span&gt; &lt;span class="no"&gt;LEVEL&lt;/span&gt; &lt;span class="no"&gt;SECURITY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="no"&gt;POLICY&lt;/span&gt; &lt;span class="n"&gt;tenant_isolation&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
  &lt;span class="k"&gt;USING&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tenant_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;current_setting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app.current_tenant'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;uuid&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;With that in place, &lt;code&gt;SELECT * FROM orders&lt;/code&gt; returns only the current tenant's rows — even with no &lt;code&gt;WHERE&lt;/code&gt; clause in the application. An endpoint that forgets to filter is now harmless instead of dangerous.&lt;/p&gt;

&lt;p&gt;We apply the same policy to customers, shipments, stock records, and the fulfillment tables. Anything that belongs to a shop gets the same guard.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that surprised us: background jobs
&lt;/h2&gt;

&lt;p&gt;The hard case was not web requests, it was jobs. A background worker processing a scheduled report has no incoming request, so there is no middleware to set the tenant context. If we ran such a job with RLS enabled and no context, it silently saw zero rows.&lt;/p&gt;

&lt;p&gt;We fixed this by making tenant context explicit in every job payload. When a job is dispatched, it records the &lt;code&gt;tenant_id&lt;/code&gt;. The worker wraps its work in the same transaction-plus-&lt;code&gt;SET LOCAL&lt;/code&gt; pattern. A job with no tenant context now fails loudly in development instead of returning empty results in production.&lt;/p&gt;

&lt;p&gt;That change surfaced several jobs that were quietly operating without proper scoping — a good kind of unpleasant surprise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Admin access and the bypass question
&lt;/h2&gt;

&lt;p&gt;Support staff occasionally need cross-tenant views. We did not create a blanket bypass role, because a bypass is exactly the hole RLS is meant to close. Instead, admin queries go through a separate, audited service that records who requested access and why. Broad access exists, but it leaves a trail.&lt;/p&gt;

&lt;p&gt;The trade-off is real: RLS adds a bit of overhead per query, and it makes local debugging more fiddly — you must remember to set the context or you see nothing. We accepted both. The overhead is small next to a query planner doing real work, and the debugging friction is a fair price for a guarantee that does not depend on human memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Put isolation in the database when the cost of getting it wrong is a data breach.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SET LOCAL&lt;/code&gt; and connection pooling go together; a plain &lt;code&gt;SET&lt;/code&gt; will eventually leak context.&lt;/li&gt;
&lt;li&gt;Background jobs need explicit tenant context — they have no request middleware to set it for them.&lt;/li&gt;
&lt;li&gt;Avoid a silent superuser bypass; audited access beats an invisible hole.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A year in, tenant isolation is no longer something we review in every pull request. It is simply true, enforced below the application layer. That is the kind of correctness you stop thinking about — which is exactly the point.&lt;/p&gt;

&lt;p&gt;Tags: #programming #webdev #database #ecommerce&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Designing an Audit Log That Survives Cross-Border Order Disputes</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Thu, 19 Nov 2026 01:17:38 +0000</pubDate>
      <link>https://dev.to/taocarts/designing-an-audit-log-that-survives-cross-border-order-disputes-4m9h</link>
      <guid>https://dev.to/taocarts/designing-an-audit-log-that-survives-cross-border-order-disputes-4m9h</guid>
      <description>&lt;h1&gt;
  
  
  Designing an Audit Log That Survives Cross-Border Order Disputes
&lt;/h1&gt;

&lt;p&gt;A parcel arrives late, the buyer opens a dispute, and the only question that matters is: what exactly happened to this order, and when? If your answer is "let me check with the warehouse," you already lost the argument.&lt;/p&gt;

&lt;p&gt;We run a cross-border storefront for reverse taobao / 1688 sourcing (the system is called Taocarts). Orders pass through more hands than a domestic shop: a customer, a purchasing agent, a consolidation warehouse, a carrier, and a local last-mile partner. Any one of them can change an address, split a shipment, or flag an item as damaged. Without a reliable audit trail, a dispute turns into a he-said-she-said mess.&lt;/p&gt;

&lt;p&gt;This is a short write-up of how we designed the audit log, and the mistakes we made along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a plain updated_at column was not enough
&lt;/h2&gt;

&lt;p&gt;Our first version had a single &lt;code&gt;updated_at&lt;/code&gt; timestamp on the orders table. It told us something changed, but not what, by whom, or from which value. That is useless in a dispute.&lt;/p&gt;

&lt;p&gt;We replaced it with an append-only &lt;code&gt;order_events&lt;/code&gt; table. Every meaningful state change writes a row:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csvs"&gt;&lt;code&gt;&lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;event_type&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;actor_id&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;from_value&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;to_value&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;trace_id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important design choice was append-only. We never update or delete an event. When a field is corrected, we write a new event rather than overwriting the old one. That gives us a full history we can replay.&lt;/p&gt;

&lt;h2&gt;
  
  
  Capturing the actor, including system actors
&lt;/h2&gt;

&lt;p&gt;Half the time the change is made by a person; the other half by a job. We distinguish them explicitly. &lt;code&gt;actor_id&lt;/code&gt; can be a user, an agent, or a system token like &lt;code&gt;auto_purchase_worker&lt;/code&gt;. During one incident, an address kept reverting and nobody could explain it. It turned out a retrying job was overwriting it. The audit log made that obvious in seconds — without it we would have blamed the customer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Attaching a trace id across services
&lt;/h2&gt;

&lt;p&gt;Purchasing, warehousing, and shipping run as separate services. A single order update can fan out into several events across them. We propagate a &lt;code&gt;trace_id&lt;/code&gt; from the original API request into every downstream event. When a buyer asks why a package stalled, we can pull every related event with one query instead of stitching logs by hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we deliberately did NOT log
&lt;/h2&gt;

&lt;p&gt;We do not log full payment card data, tokens, or raw personal identifiers. Those stay in their own encrypted stores; the audit log keeps only references. Keep the log useful without turning it into a liability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retention and cold storage
&lt;/h2&gt;

&lt;p&gt;Audit rows grow fast. We keep 12 months hot for fast dispute lookup, then archive to cold storage. Disputes older than that are rare, and when they happen the archive is still queryable, just slower.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Append-only beats update-in-place, every single time.&lt;/li&gt;
&lt;li&gt;Log the actor, not just the timestamp — "who" resolves most disputes.&lt;/li&gt;
&lt;li&gt;A trace id is cheap to add early and painful to retrofit later.&lt;/li&gt;
&lt;li&gt;Keep sensitive data out; store references instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you operate a multi-party order flow, build the audit trail before the first dispute, not after. It is one of those features you never notice until the day it saves you.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Keeping Warehouse Inventory in Sync When Suppliers Go Silent</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Tue, 17 Nov 2026 01:24:25 +0000</pubDate>
      <link>https://dev.to/taocarts/keeping-warehouse-inventory-in-sync-when-suppliers-go-silent-3glg</link>
      <guid>https://dev.to/taocarts/keeping-warehouse-inventory-in-sync-when-suppliers-go-silent-3glg</guid>
      <description>&lt;h1&gt;
  
  
  Keeping Warehouse Inventory in Sync When Suppliers Go Silent
&lt;/h1&gt;

&lt;p&gt;Our sourcing platform pulls stock and price data from a handful of upstream marketplaces. Those feeds are not dependable. A supplier can go quiet for an hour, send a partial update, or replay an old event out of order. When that happens, the number we show a buyer and the number actually sitting in the warehouse drift apart — and a wrong inventory count turns into a cancelled order.&lt;/p&gt;

&lt;p&gt;We spent the last quarter tightening the sync layer between supplier events and our warehouse records. Here is the approach and the failure modes we hit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Treat every incoming update as untrusted
&lt;/h2&gt;

&lt;p&gt;The first rule: an event from a supplier is a claim, not a fact. We validate it before it touches inventory — check the shape, check the source, and check that it is not older than the state we already applied. That last check matters more than it sounds.&lt;/p&gt;

&lt;p&gt;Early on, we applied events in arrival order. A delayed "back in stock" message could land after a newer "out of stock" one, and suddenly we were selling something that was gone. Now every event carries the provider timestamp, and we store a &lt;code&gt;last_applied_at&lt;/code&gt; per SKU. If an incoming event is older, we drop it. Ordering by the producer's clock, not the network's, fixed a whole class of phantom-stock bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Absorb duplicate deliveries at the storage layer
&lt;/h2&gt;

&lt;p&gt;Suppliers retry aggressively when they do not get an ack. That means the same stock update can arrive several times. We give each event a provider-side identifier and put a unique constraint on it in the &lt;code&gt;supplier_events&lt;/code&gt; table. A repeated delivery fails the insert quietly and is ignored. This is cheap insurance, and it keeps our counters from being decremented twice for one physical sale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Put a retry buffer between the feed and the warehouse
&lt;/h2&gt;

&lt;p&gt;When the warehouse service is briefly unavailable, we do not want to lose the update. Incoming events are written to a durable buffer table and marked pending. A worker picks them up, applies them, and marks them done. On failure, the attempt count goes up and the event is scheduled again with exponential backoff and a bit of jitter, so a burst of failures does not come back as a synchronized wave.&lt;/p&gt;

&lt;p&gt;After a fixed number of attempts, an event moves to a dead-letter list. That list is not a graveyard — it is how we notice a supplier silently changed a field name. We alert on it, and a small internal tool lets us replay an event once the root cause is fixed. The first week we enabled it, we caught two schema changes we would otherwise have found through customer complaints.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconcile, do not just trust the stream
&lt;/h2&gt;

&lt;p&gt;Even with all of this, streams drift. So we run a periodic reconciliation job that compares our recorded counts against a snapshot from the warehouse system and flags mismatches above a threshold. It runs off-peak and writes discrepancies to a report rather than silently "correcting" numbers. A human looks at the report before we adjust anything, because an automatic overwrite can hide a real problem.&lt;/p&gt;

&lt;p&gt;The sync layer in our Taocarts platform — a cross-border reverse-shopping system for Taobao/1688 sourcing and consolidation — works this way now. React on the front end, Laravel services behind it, and a warehouse module that treats supplier data as untrusted input. The result is fewer oversells and, honestly, calmer support mornings.&lt;/p&gt;

&lt;p&gt;If you integrate third-party inventory feeds, three habits pay off quickly: order by the producer's timestamp, deduplicate at the database, and reconcile on a schedule. Streams lie sometimes; a reconciliation job is the honest second opinion.&lt;/p&gt;

&lt;p&gt;Tags: #programming #webdev #ecommerce #automation&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>A Two-Stage QC Process for Returned Cross-Border Parcels</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Sun, 15 Nov 2026 01:38:24 +0000</pubDate>
      <link>https://dev.to/taocarts/a-two-stage-qc-process-for-returned-cross-border-parcels-2nnh</link>
      <guid>https://dev.to/taocarts/a-two-stage-qc-process-for-returned-cross-border-parcels-2nnh</guid>
      <description>&lt;h1&gt;
  
  
  A Two-Stage QC Process for Returned Cross-Border Parcels
&lt;/h1&gt;

&lt;p&gt;In reverse-Taobao operations, a parcel coming back is not the end of the story. It is the start of a decision: can this item be resold, or does it become waste? Get that decision wrong and you either ship a damaged product to the next buyer or you destroy margin by scrapping something perfectly fine.&lt;/p&gt;

&lt;p&gt;We run a two-stage quality check on every returned parcel before it re-enters inventory. Here is the workflow and why it saves us money.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stage 1: intake photo, before anything moves
&lt;/h2&gt;

&lt;p&gt;The moment a return arrives at the overseas warehouse, the staff takes a set of photos against a fixed checklist — outer packaging, seal, and any visible defect. These photos are attached to the parcel record in our system &lt;em&gt;before&lt;/em&gt; the item is moved, shelved, or opened further.&lt;/p&gt;

&lt;p&gt;The point is tamper evidence. If a later dispute claims "it arrived broken," we already have the intake photo timestamped at warehouse entry. This alone killed half of our false damage claims.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stage 2: condition grading, then a routing decision
&lt;/h2&gt;

&lt;p&gt;After intake, the item is graded into one of three buckets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Grade A&lt;/strong&gt; — unopened or like-new, resell as normal stock.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grade B&lt;/strong&gt; — minor packaging flaw, resell at a discount with the flaw disclosed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grade C&lt;/strong&gt; — real defect, routed to disposal or supplier return, never back to the shelf.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The grade is recorded against the parcel, and only Grade A and B are allowed to flip back to "available" in inventory. Grade C is physically separated so it cannot be accidentally shipped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why two stages and not one
&lt;/h2&gt;

&lt;p&gt;A single inspection at the end is tempting, but it mixes "prove it arrived safe" with "decide if it sells." Separating them means the intake photo is a pure evidence capture, while grading is a business decision that can involve a human for edge cases. The system enforces the order: no grading without an intake photo on file.&lt;/p&gt;

&lt;h2&gt;
  
  
  The data payoff
&lt;/h2&gt;

&lt;p&gt;Over a quarter, this let us recover roughly a third of returned items into sellable stock instead of writing them off. For cross-border, where reverse logistics already eats margin, that recovery is the difference between a return being a loss and being a small cost.&lt;/p&gt;

&lt;p&gt;The lesson generalizes: a return is not a dead end. Treat it as inventory that needs a verdict, capture evidence first, grade second, and let the system refuse to skip steps. Everything else is packaging.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Load Testing Our Checkout Pipeline Without Taking Down Production</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Fri, 13 Nov 2026 01:32:18 +0000</pubDate>
      <link>https://dev.to/taocarts/load-testing-our-checkout-pipeline-without-taking-down-production-1324</link>
      <guid>https://dev.to/taocarts/load-testing-our-checkout-pipeline-without-taking-down-production-1324</guid>
      <description>&lt;p&gt;--&amp;gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Load Testing Our Checkout Pipeline Without Taking Down Production
&lt;/h1&gt;

&lt;p&gt;Every cross-border commerce team learns the same lesson during peak season: the checkout path is the one place you cannot afford to fall over, and it is also the place you are most afraid to stress-test. At Taocarts, a platform that mirrors Chinese marketplaces (Taobao, 1688) into overseas storefronts and consolidates purchasing and shipping, we spent a peak season watching our checkout bend before we finally built a safe way to break it on purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  The naive approach fails quietly
&lt;/h2&gt;

&lt;p&gt;Our first instinct was to point a load tool at the production checkout URL and crank the concurrency. It "worked" once, then we agreed never to do it again — a misconfigured ramp brought the live storefront down for nine minutes during a real promo. Testing against production is too risky; not testing at all is worse.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we actually do now
&lt;/h2&gt;

&lt;p&gt;We run load tests against a full staging environment that mirrors production's topology: same Laravel API, same database engine, same queue workers, but isolated tenant data and a separate payment gateway in sandbox mode. The goal is never to "test the real thing", it is to test the same code and the same shape of traffic.&lt;/p&gt;

&lt;p&gt;The traffic shape matters more than the volume. A real checkout burst is not uniform. It is a sharp ramp at a promo start, a long plateau, then a second spike when the "last chance" reminder fires. We replay recorded traffic patterns from previous peaks, scaled up, rather than a synthetic flat flood.&lt;/p&gt;

&lt;h2&gt;
  
  
  The parts that actually break
&lt;/h2&gt;

&lt;p&gt;Under load, the checkout path fails in predictable places. Database connections exhaust first because every request opens a short-lived read. We moved read-heavy lookups (product display, exchange-rate snapshots) behind a cache with a short TTL, so a spike in browsing does not translate one-to-one into database hits.&lt;/p&gt;

&lt;p&gt;The second failure is the payment confirmation step. When the gateway slows, requests pile up waiting for a callback ACK. We capped in-flight payment confirmations per worker and pushed the slow part onto a queue, so a slow gateway degrades gracefully instead of cascading.&lt;/p&gt;

&lt;p&gt;The third is email and notification fan-out. Sending a confirmation per checkout synchronously is fine at 10 requests per second and fatal at 400. We made all notifications fire-and-forget through the queue.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we know it worked
&lt;/h2&gt;

&lt;p&gt;We do not trust a single passing run. Each test produces a report: p95 and p99 latency at target concurrency, error rate, and where the saturation point was. If p99 climbs past our threshold before we reach target load, the test "failed" by design and we go fix the bottleneck. The point is to find the wall in staging, not in front of real buyers.&lt;/p&gt;

&lt;h2&gt;
  
  
  The payoff
&lt;/h2&gt;

&lt;p&gt;After we standardized this, our last two promo peaks passed without a checkout incident. More importantly, when something does saturate, we now have a number for where, instead of a 3 a.m. guessing game.&lt;/p&gt;

&lt;p&gt;Load testing checkout is not glamorous, and it will never be the demo slide. But the checkout is where revenue is won or lost in milliseconds — testing it safely, against a mirror of production, is one of the highest-leverage things a commerce backend team can do.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Building a Real-Time Parcel Tracking Feed with WebSockets</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Thu, 12 Nov 2026 01:29:23 +0000</pubDate>
      <link>https://dev.to/taocarts/building-a-real-time-parcel-tracking-feed-with-websockets-1k3a</link>
      <guid>https://dev.to/taocarts/building-a-real-time-parcel-tracking-feed-with-websockets-1k3a</guid>
      <description>&lt;p&gt;--&amp;gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Building a Real-Time Parcel Tracking Feed with WebSockets
&lt;/h1&gt;

&lt;p&gt;When you run a cross-border reverse-commerce platform, the single most repeated question from buyers is not "how much" — it is "where is my parcel". On Taocarts, a system that mirrors products from Chinese marketplaces (Taobao, 1688) into overseas storefronts and consolidates purchasing, that question shows up hundreds of thousands of times a day. Our first version answered it badly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The polling mistake
&lt;/h2&gt;

&lt;p&gt;The early dashboard fetched the latest tracking status from our backend on a fixed interval — every 30 seconds per open tab. It worked in the demo and fell over in reality. With a few thousand concurrent buyers watching their parcels, that was a constant stream of identical read queries hammering the same endpoints. Worse, most polls returned "no change", so we were burning database connections to say nothing.&lt;/p&gt;

&lt;p&gt;The second problem was freshness. A parcel can move three statuses in the time between two polls. Buyers refreshed manually, saw stale data, and opened support chats asking the same thing our server already knew. The chat volume was purely an artifact of bad UX, not real issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why WebSockets, not SSE or long-poll
&lt;/h2&gt;

&lt;p&gt;We considered Server-Sent Events. SSE is simpler and rides on HTTP, which is appealing. But our tracking updates come from multiple sources — carrier webhooks, manual scans at the warehouse, and batch imports — and we wanted bidirectional room to let clients subscribe to specific parcel IDs rather than a global stream. WebSockets gave us a clean subscription model: open one connection, send a &lt;code&gt;subscribe&lt;/code&gt; frame with the parcel IDs you care about, and receive only the deltas.&lt;/p&gt;

&lt;h2&gt;
  
  
  The architecture
&lt;/h2&gt;

&lt;p&gt;The transport layer is a small Node service behind the main Laravel API. Responsibilities are deliberately narrow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authenticate the socket using the same session token as the REST API.&lt;/li&gt;
&lt;li&gt;Accept &lt;code&gt;subscribe&lt;/code&gt; / &lt;code&gt;unsubscribe&lt;/code&gt; frames keyed by parcel ID.&lt;/li&gt;
&lt;li&gt;Hold a lightweight in-memory map of &lt;code&gt;parcelId -&amp;gt; set of sockets&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Subscribe to a Redis pub/sub channel where all tracking updates are published.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The source of truth for tracking lives in the Laravel service. Whenever a status changes — a carrier webhook lands, a warehouse scan happens, a batch import finishes — Laravel publishes a small event to Redis: &lt;code&gt;tracking:updated&lt;/code&gt; with the parcel ID and the new node. The Node socket service is just another subscriber. It looks up which sockets care about that parcel ID and pushes the delta. Nothing about tracking state is stored in the socket service itself; it is a pure fan-out.&lt;/p&gt;

&lt;p&gt;Keeping state out of the socket layer was the key decision. If the socket service restarts, it loses nothing but open connections, and clients simply reconnect and re-subscribe. The real data is always rebuilt from the API on reconnect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling the messy parts
&lt;/h2&gt;

&lt;p&gt;Connection drops are normal, not errors. We use a heartbeat every 25 seconds; a socket that misses two heartbeats is closed and the client reconnects with exponential backoff. On reconnect, the client sends its current subscribed IDs again, so it never misses a node that changed while it was away — it just replays the latest state from the API.&lt;/p&gt;

&lt;p&gt;Backpressure matters. If a carrier dumps ten thousand updates in a burst, we do not push them one-by-one synchronously. We batch per socket on a short tick (say 200ms) and coalesce: if a parcel changed twice in that window, the client gets the final node, not both. Buyers want "where it is now", not a high-frequency play-by-play.&lt;/p&gt;

&lt;p&gt;We also learned to cap subscriptions per connection. A single tab subscribing to ten parcels is reasonable; a buggy client opening ten tabs and subscribing to a hundred each is not. We enforce a per-connection limit and a global connection ceiling, rejecting politely beyond that.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed
&lt;/h2&gt;

&lt;p&gt;Support tickets about "where is my parcel" dropped sharply because the answer now arrives before the buyer thinks to ask. Server load actually went down despite more live connections, because we replaced a storm of polling reads with a push model that only fires on real change.&lt;/p&gt;

&lt;p&gt;The lesson that stuck with the team: real-time is not about pushing everything faster, it is about pushing only what changed, to only the people who asked. WebSockets gave us the subscription primitive to do exactly that without bloating the core service.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Handling Multi-Currency Rounding in a Cross-Border Store (and Why Refund Tags Matter)</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Tue, 10 Nov 2026 01:37:10 +0000</pubDate>
      <link>https://dev.to/taocarts/handling-multi-currency-rounding-in-a-cross-border-store-and-why-refund-tags-matter-21k4</link>
      <guid>https://dev.to/taocarts/handling-multi-currency-rounding-in-a-cross-border-store-and-why-refund-tags-matter-21k4</guid>
      <description>&lt;p&gt;--&amp;gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Handling Multi-Currency Rounding in a Cross-Border Store (and Why Refund Tags Matter)
&lt;/h1&gt;

&lt;p&gt;When you run a reverse-Taobao store that sells to buyers in USD, EUR, KRW, and JPY at the same time, currency is not a display detail — it is a correctness problem. A price of ¥99 might show as $13.71, and on refund it becomes $13.72. Multiply that by thousands of orders and you either over-charge buyers or leak cents every single day.&lt;/p&gt;

&lt;p&gt;At Taocarts (a cross-border independent-site system built for reverse-Taobao and 1688 sourcing), we treat money as integer minor units end to end. The storefront shows a friendly decimal, but every calculation — tax, shipping, coupon, refund — runs on the smallest currency unit (cents, won, yen). We never round in the middle of a chain; we round exactly once, at the edge, when presenting to the user.&lt;/p&gt;

&lt;p&gt;The classic trap is "naive reversal". A common bug is to recompute the refund from the current exchange rate instead of replaying the original transaction. Rates move between purchase and return, so the buyer gets back a different amount than they paid. Our fix: store the original settlement amount per order in its original currency, and the refund is a reversal of that recorded value, not a fresh conversion. For a partial refund we split the recorded amount proportionally and keep the remainder as a precise fraction, never a rounded guess.&lt;/p&gt;

&lt;p&gt;Multi-currency rounding also bites on aggregated shipments. When three items from different suppliers merge into one box, each has its own settled currency. We keep a per-line settlement ledger so the consolidated invoice still reconciles to the sum of its parts. The UI shows one total, but the ledger underneath is strictly additive from immutable line items.&lt;/p&gt;

&lt;p&gt;Then there is the refund-reason problem. If you only log "refunded", you learn nothing. We attach structured reason tags at refund time — size, damage, late delivery, wrong item — and aggregate them per SKU. That turns a cost center into a feedback loop: the SKU with the highest "size" return rate tells you the size chart needs fixing before you reorder.&lt;/p&gt;

&lt;p&gt;A refund endpoint must also be idempotent. Network retries can fire the request twice; if each attempt creates a new payout, you double-refund. We key the operation on a client-generated idempotency key and persist the first outcome, so a retry returns the original result. Combined with the immutable ledger, a refund is safe to retry and safe to audit.&lt;/p&gt;

&lt;p&gt;On presentation we use half-even (banker's) rounding so that across high volume the rounding errors cancel rather than skew. It is invisible to a single buyer but matters when finance reconciles the monthly statement against the processor.&lt;/p&gt;

&lt;p&gt;The engineering takeaway is simple: keep money as integers, replay original transactions instead of recomputing, tag every refund with a reason, and make the endpoint idempotent. Do those four things and multi-currency stops being a daily leak and becomes just another report you read on Monday.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Syncing Shopify Orders Back to Inventory to Prevent Oversell</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Sun, 08 Nov 2026 01:30:11 +0000</pubDate>
      <link>https://dev.to/taocarts/syncing-shopify-orders-back-to-inventory-to-prevent-oversell-34ik</link>
      <guid>https://dev.to/taocarts/syncing-shopify-orders-back-to-inventory-to-prevent-oversell-34ik</guid>
      <description>&lt;p&gt;--&amp;gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Syncing Shopify Orders Back to Inventory to Prevent Oversell
&lt;/h1&gt;

&lt;p&gt;When you run a reverse-Taobao style storefront that pushes products to Shopify, the hard problem is not "how to list" — it is "how to keep stock honest across channels." Sell the same SKU on your own site and on Shopify, and a customer on one side can buy the last unit while the other side still shows it in stock. Oversell follows, then a manual apology, then a refund.&lt;/p&gt;

&lt;p&gt;Taocarts is a reverse-cross-border system that lets sellers list Chinese marketplace goods (Taobao, 1688, and others) onto storefronts like Shopify, Coupang, Woo, and Base, then syncs orders back for consolidated purchasing. The Shopify leg of that flow taught us a few things about inventory write-back.&lt;/p&gt;

&lt;h2&gt;
  
  
  The naive approach fails fast
&lt;/h2&gt;

&lt;p&gt;The obvious design is: Shopify order comes in → decrement a local counter → done. It breaks the moment two orders land within the same second, or when the webhook arrives twice (Shopify does redeliver). You end up with a counter that drifts below zero or disagrees with reality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Treat stock as an event log, not a counter
&lt;/h2&gt;

&lt;p&gt;We model inventory as append-only events: &lt;code&gt;RESERVED&lt;/code&gt;, &lt;code&gt;SOLD&lt;/code&gt;, &lt;code&gt;RESTOCKED&lt;/code&gt;, &lt;code&gt;ADJUSTED&lt;/code&gt;. The "available" number is a derived sum, never a field you decrement in place. A Shopify order appends a &lt;code&gt;RESERVED&lt;/code&gt; event keyed by &lt;code&gt;(shopify_order_id, line_item_id)&lt;/code&gt;. A duplicate webhook produces the same key, and a unique constraint drops the second write silently. No double reservation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write back only after the source confirms
&lt;/h2&gt;

&lt;p&gt;We do not decrement on "order created." We reserve on creation, then move to &lt;code&gt;SOLD&lt;/code&gt; only when the source marketplace confirms the purchase actually went through (1688/taobao confirmations are async). This two-phase step avoids the classic bug where an abandoned cart or a failed procurement leaves stock locked forever.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconcile, don't trust
&lt;/h2&gt;

&lt;p&gt;Once a day we pull Shopify's inventory API and diff it against our derived available count. Any mismatch opens a reconciliation ticket instead of auto-correcting — auto-correcting hides the bug that caused the drift. Over a month this surfaced three real issues: a webhook we were not subscribed to, a batch job that double-counted restocks, and a timezone bug in our nightly job.&lt;/p&gt;

&lt;p&gt;The lesson: cross-channel inventory is a consistency problem, not a counter problem. Model it as events, make every external write idempotent by key, and reconcile on a schedule. Do that and oversell stops being something you explain to customers and starts being something your dashboards catch first.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>How Taocarts Generates Locale-Aware Watermarks for Product Images</title>
      <dc:creator>Taocarts跨境</dc:creator>
      <pubDate>Sat, 07 Nov 2026 01:24:40 +0000</pubDate>
      <link>https://dev.to/taocarts/how-taocarts-generates-locale-aware-watermarks-for-product-images-d1n</link>
      <guid>https://dev.to/taocarts/how-taocarts-generates-locale-aware-watermarks-for-product-images-d1n</guid>
      <description>&lt;p&gt;When you sell the same product across Shopify, Coupang, Woo, and Base, the image that works in English can quietly break in another market. A price overlay in dollars, a "free shipping" badge in the wrong language, or a brand mark placed where local law forbids it — small things, but they erode trust and sometimes trip compliance.&lt;/p&gt;

&lt;p&gt;We stopped hand-editing images per market. Instead, we generate locale-aware watermarks at upload time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with one global image
&lt;/h2&gt;

&lt;p&gt;A listing photo is rarely just a photo. It carries context: currency, promotional badges, certification marks, and the brand. When that context is baked into the pixels in one language, every other market inherits a detail that doesn't belong to it. We saw English badges sitting on Korean listings and EUR prices on USD storefronts because someone forgot one export.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our approach: templates, not manual edits
&lt;/h2&gt;

&lt;p&gt;Each locale has a watermark template: position, font, allowed badge set, and a translation key. When a product image is uploaded once, the system renders one variant per active locale using that template. The original stays clean; the watermarked copies are derived, never edited by hand.&lt;/p&gt;

&lt;p&gt;Technically this is a queue job. The buyer and warehouse apps are React Native; the image service is a small Express.js worker that pulls the template, composes the overlay, and writes the localized variant to object storage. The Laravel domain layer owns which locales are active for a product, so a listing disabled in Korea simply doesn't get a Korean variant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it matters beyond cosmetics
&lt;/h2&gt;

&lt;p&gt;Two concrete wins. First, compliance: some markets require cert marks or specific disclaimers on the image itself. Templates make that a config change, not a redesign. Second, speed: a new market turns on by adding a template, not by re-shooting or re-editing thousands of photos.&lt;/p&gt;

&lt;p&gt;The part we're proud of is boring on purpose — nothing clever, just a deterministic pipeline that turns "one image, many correct overlays" into a default behavior instead of a manual chore.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
  </channel>
</rss>
