Once a month my app has a ton of usage and I always run into the Too many requests 429 error.
I am trying to optimize the queues and jobs to manage that, but as the platform is getting more and more users, I am not able to optimize it and running that in enough time.
I have seen I could use the dev api key, to bypass that limit.
Is that a good practice? Or what other options do I have?
Thanks
/**
- Pace an Appwrite SDK call through the global token bucket. Retries on 429
- with exponential backoff + jitter, respecting
Retry-After/ `X-RateLimit- - Reset` when present. Any non-429 error is rethrown immediately.
- Usage:
- const doc = await withAppwriteCall(() =>
- TypeScript
tablesDB.getRow({ databaseId, tableId, rowId }) - )
- Wrap at the REPO boundary, not at every call site — see the repo files for
- the canonical pattern. */ export async function withAppwriteCall<T>( fn: () => Promise<T>, opts: WithAppwriteCallOptions = {} ): Promise<T> { const maxRetries = opts.maxRetries ?? MAX_RETRIES const label = opts.label ?? 'appwrite' let attempt = 0
while (true) { const { waitedMs } = await acquireToken() stats.calls += 1 stats.totalWaitMs += waitedMs if (waitedMs > 0) stats.throttleWaits += 1
try {
return await fn()
} catch (err) {
if (!isRateLimitError(err)) throw err
// 429 — apply retry logic.
stats.rateLimitHits += 1
if (attempt >= maxRetries) {
throw new AppwriteThrottleExhausted(
`[${label}] giving up after ${attempt + 1} attempts on 429`,
attempt + 1
)
}
stats.retries += 1
const explicit = readRetryAfter(err)
const sleepMs = explicit ?? backoffMs(attempt)
console.warn(
`[throttle] ${label} 429 attempt=${attempt + 1}/${maxRetries + 1} sleep=${sleepMs}ms (${explicit ? 'retry-after' : 'exponential'})`
)
await sleep(sleepMs)
attempt += 1
// Loop continues; we'll acquire a fresh token and retry.
}
} } also tryied using this
Recommended threads
- 401 - Project not accessible in this reg...
Hi Appwrite team, I’m experiencing a Cloud Console issue with my NYC region project. Problem: - Some Console pages return: “401 - Project is not accessible ...
- 401 - Project not accessible, Singapore ...
Hi, I'm getting a 401 error when I try to open my project from the Appwrite Cloud console dashboard. Project ID : sgp-6a04326f002bd04cc420 Region : Singap...
- Hi, I'm getting a 403 error when I try t...
Project ID : 6797cdc1000c5078d8b9 Region : Frankfurt (fra) Error : "Project is paused due to inactivity. Please restore it from the console to resume o...