Problem
backend/src/lib/storage.ts — getClient() creates a new S3Client(...) on every call, and every exported function calls it:
function getClient(): S3Client {
return new S3Client({ region: "auto", endpoint: ..., credentials: ... });
}
export async function uploadFile(...) {
const client = getClient(); // new instance every upload
...
}
AWS SDK clients are heavyweight — they initialise an HTTP agent, retry logic, and credential resolution per instantiation. Creating one per request prevents keep-alive connection reuse and adds unnecessary GC pressure, especially during upload spikes (50/hr rate limit window).
Fix
Hoist the client to a module-level singleton, lazy-initialised on first use:
let _client: S3Client | null = null;
function getClient(): S3Client {
if (!_client) _client = new S3Client({ ... });
return _client;
}
Problem
backend/src/lib/storage.ts—getClient()creates anew S3Client(...)on every call, and every exported function calls it:AWS SDK clients are heavyweight — they initialise an HTTP agent, retry logic, and credential resolution per instantiation. Creating one per request prevents keep-alive connection reuse and adds unnecessary GC pressure, especially during upload spikes (50/hr rate limit window).
Fix
Hoist the client to a module-level singleton, lazy-initialised on first use: