You asked about a handler skeleton and whether to store processed event ids. Yes, store them. Here's the shape I use:
Check the signature on the raw body, before you parse anything. Insert the event id into a table with a unique constraint. If the insert fails, you've seen it before, so return 200 and stop. Fetch the subscription from Stripe and write that, not the event payload. Add a revision column and update with WHERE revision = , so two handlers running at once can't overwrite each other. Return 200.
Re-fetching fixes the stale state, but it won't stop a retry from sending the same email twice. The event id table is what stops that. I put a tested version of this together for Postgres/Supabase. It's on my GitHub (navalpro8-lgtm, repo stripe-subscription-sync). It's mine, and not audited, so treat it as a reference. i couldnt paste the link so try going to my repo manually