We're experiencing an issue with our serverless API route that handles reminder emails. Despite implementing safety checks that should prevent reminders from being sent more frequently than every 12 hours, we continue to see reminders being sent at much shorter intervals in our production environment. The same code works correctly in our local development environment.
Technical Details
Endpoint: /api/reminders
Runtime: Edge
Dynamic: force-dynamic
Expected Behavior:
- Our cron job calls this endpoint periodically
- The endpoint processes reminder eligibility with safety checks that prevent any reminders from being sent to the same recipient more frequently than every 12 hours
- The safety check code looks like this:
// SAFETY CHECK: Enforce minimum time between reminders regardless of other logicif (sme.last_reminder_sent) {const lastSent = new Date(sme.last_reminder_sent);const now = new Date();const hoursSinceLastReminder = (now.getTime() - lastSent.getTime()) / (1000 * 60 * 60);
// Minimum 12 hours between any reminders as a safety measureconst MINIMUM_HOURS_BETWEEN_REMINDERS = 12;
if (hoursSinceLastReminder < MINIMUM_HOURS_BETWEEN_REMINDERS) {// Block reminder and log the blockreturn {success: false,projectId: project.id,smeId: sme.sme_id,reminderType: null,message: `Safety check: Only ${Math.round(hoursSinceLastReminder)} hours since last reminder (minimum: ${MINIMUM_HOURS_BETWEEN_REMINDERS})`};}}Actual Behavior:
- In production, reminders are being sent much more frequently (every 3-6 hours)
- Local testing confirms the safety check is working properly
- Database records show the
last_reminder_sentfield is being updated correctly - Our enhanced logging (using console.error) shows the safety checks are working locally
And no logs on vercel:

Questions:
- Could multiple concurrent executions of the same serverless function be occurring in Vercel, bypassing our safety checks?
- Is there a caching issue where stale data is being used in subsequent function executions?
- Are serverless functions in Vercel potentially running with different timestamps/timezones than expected?
- Could there be issues with database connection pooling or transaction isolation that's causing race conditions?
- Is there a way to better debug or trace the execution of this function in the Vercel environment?
- Anything else?
Additional info
- We're using Supabase for our database
- Our development environment is Next.js 14
- We don't see any relevant errors in the Vercel Function logs
- The issue seemed to start recently without code changes in this area
We'd appreciate any insights or debugging suggestions to help resolve this production-only issue. Please let us know what additional information you might need.
Thank you for your help.