valstar.dev
TTCTheo's Typesafe Cult
•Created by valstar.dev on 6/11/2023 in #questions
How would you track API usage per user group on a series of edge functions
I have a need to track usage of some APIs (per group) for a set of APIs that will be deployed as edge functions with Vercel.
Writing a
UPDATE usage SET callcount += 1 WHERE id = $1
on every request seems like overkill, and using something like Vercel kv as a buffer would double the cost per API call.
Typically if I was building a standard server component I would have it store a series of usage stats in a singleton that would flush out to the database over time, but that wont work with edge functions. Not sure what other approaches people might have or suggest. (the core database for the project is postgres with Vercel postgres)2 replies