Better AuthBA
Better Auth•6mo ago
ehahn9

Advice: how to authenticate high-frequency endpoints?

I have an api endpoint which is being hit very frequently (/api/thumbnail/:provider/:id). That endpoint needs to fetch the account associated with that provider (e.g. getting/refreshing the access token) and then makes an api request to the provider (e.g. google drive) with the bearer token, etc.

Alas, this is overwhelming supabase and I'm getting 504 errors 😦

What should I do? I'd like not to re-invent the wheel so perhaps someone can give me some advice?

Some things I'm thinking about:

  1. turn on cookieCache (duh!) - but that only caches the session not the accounts
    • so only a 50% solution
  2. store more of the account data in the session cookie (how do I do that?)
  3. use a redis cache for the account data instead of getting it from supabase
  4. use redis for the better-auth database (I think I'd need to write my own adaptor)?
  5. do a ton of nasty work on the client to pool <img> src requests with a batch thumbnail api
Advice appreciated!
Was this page helpful?