Case study: a successful top-up still showed insufficient balance because the cache was stale
A real investigation found that a successful database write did not immediately change the read path; a stale balance cache kept pre-authorization rejecting requests.
The symptom: a top-up succeeded, but video requests still failed
On November 21, 2026, a user submitted several video jobs and received insufficient_user_quota. It looked like a genuine low-balance case: the error showed roughly ¥1.46 available while a single pre-authorization needed about ¥1.60 to ¥1.72. The user then completed several top-ups, yet the next requests returned the same insufficient-balance error.
This is easy to mislabel as “the top-up never arrived,” and it is also easy to tell the user to pay again. The correct first step is to align three timestamps: when the order succeeded, when the database balance changed, and where the failed request read its balance. Without that timeline, payment failure, a write failure, a stale cache, and a genuinely oversized request look identical.
Investigation: separate payment, database, and cache
1. Verify the order state
Start by checking whether each order is successful, whether the amount belongs to the target user, and whether there are duplicate callbacks or pending orders. This investigation confirmed several Alipay orders totaling ¥100 had succeeded before the failed requests. Two other orders were still pending and could not be counted. That ruled out the case where a payment page looked successful but the order had not completed.
2. Verify the database balance
Next, read quota and used_quota and convert the internal quota unit to the displayed currency. The database balance was already well above the roughly ¥1.46 shown in the error, so the database write had succeeded. Quota is not always stored as a direct currency value. The investigation must confirm units, exchange rate, and group multiplier instead of comparing raw numbers.
3. Find the actual read path
Finally, inspect the balance lookup. When a forced refresh is not requested, this path prefers a user Redis cache and falls back to the database only when the cache is missing or expired. The top-up function updated the database but did not invalidate the user balance cache after a successful transaction. For a short window after the top-up, requests could therefore keep reading the pre-top-up balance of about ¥1.46 and fail pre-authorization.
Root cause: the write and read paths had no closed loop
The root cause was not payment rejection and not a sudden price change in the video model. Two storage layers had different update timing: the top-up transaction changed the database while the read path kept using an old cache. Once the cache expired or was removed, the balance could look correct again. That later observation does not disprove the earlier stale-cache window.
An asynchronous video request performs pre-authorization first. If that step reads an insufficient balance, the request may never reach the upstream task submission. The symptom looks like a video-provider rejection, but the wallet rejected it at the entrance. Investigation must connect the request ID, pre-authorization log, refund log, and upstream submission log rather than relying on one frontend error line.
Fix: invalidate the user cache after a successful top-up
The fix is small but must cover every write path: after the database transaction successfully changes a user's balance, call one shared user-cache invalidation routine. The repair covered Alipay, Stripe, Creem, Waffo, Waffo Pancake, and administrator top-up paths. Failed orders, pending orders, and rolled-back transactions must not invalidate or increase a balance prematurely.
Verification needs two groups of tests. One checks that the first API request after a successful top-up reads the new database balance. The other checks that a failed or rolled-back top-up does not increase the balance incorrectly. For asynchronous jobs, also confirm that a pre-authorization failure creates no upstream task and that an already submitted job follows the existing refund rule when it fails.
Checklist
- Is the order
success, rather than pending or only successful on a payment screen?
- Do the order owner, currency, group, and amount match the target account?
- Are
quotaandused_quotaconverted using the correct unit?
- Does the balance endpoint prefer Redis or another cache?
- Does every successful top-up transaction invalidate that cache?
- Can pre-authorization, upstream submission, and refund logs be joined by request ID?
- Did the failed request really create no upstream job?
- After the fix, were successful, failed, concurrent, and expired-cache paths tested?
“The database changed” does not mean “the next request must see the new value.” For balances and pre-authorization, validate the write path, cache path, and asynchronous task path together.
1: SalpX API Reference describes video endpoints as asynchronous jobs and states that failed jobs are automatically refunded: https://www.salpx.com/api-docs/
Sources & attribution
This article references the public materials listed below. Analysis and wording are SalpX's own; quoted material remains the property of its original authors and publishers.
- SalpX API Reference — SalpX · accessed 2026-11-21Note:SalpX's official documentation describes asynchronous video jobs as submit-then-poll and states that failed jobs are refunded; the case facts are anonymized from an internal operations log on November 21, 2026.
One key for Claude, GPT and 50+ models
The SalpX gateway is OpenAI-SDK compatible. Point base_url at https://www.salpx.com/v1 and you are done.