{
  "id": 626053,
  "title": "How We Reset Monthly Quotas Without Race Conditions or Cron Drift",
  "url": "https://urgent.news/2026/08/12/how-we-reset-monthly-quotas-without-race-conditions-or-cron-drift",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-12T03:26:05.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/anand_rathnas_d5b608cc3de/how-we-reset-monthly-quotas-without-race-conditions-or-cron-drift-35j6"
  },
  "original_language": "en",
  "account": "This article explains how to reset monthly usage quotas for customers billed on a monthly or yearly subscription without causing race conditions or cron drift. The solution involves using Spring Scheduler and Postgres advisory locks. Two key points are:\n\n1. The job runs once per calendar month, regardless of the number of app instances, using a cron schedule that staggered 5 minutes past midnight UTC on the first of the month.\n2. An instance-level advisory lock is used, keyed on an integer, which auto-releases at transaction end. This prevents multiple instances from running the reset simultaneously.\n\nThe reset is performed by executing a single SQL UPDATE across the whole table inside a transaction, which is more efficient than fetching each user and saving them individually. Additionally, an admin override is provided for emergency situations.",
  "summary": "This article was originally published on Jo4 Blog . If you're billing monthly via Stripe or RevenueCat, it's tempting to reset usage quotas inside your webhook handler. The customer pays → invoice fires → you zero out their urlCount . Clean. One source of truth. It works for some customers. Two customer types it doesn't work for, and they're both yours: Yearly subscribers. Their payment event…",
  "key_points": [
    "Reset monthly quotas without race conditions or cron drift",
    "Use Spring Scheduler with 5-minute past midnight UTC cron",
    "Instance-level advisory lock prevents simultaneous resets"
  ],
  "editors_take": "This approach ensures reliable monthly quota resets for subscribers by preventing simultaneous execution across app instances and guaranteeing a single, efficient database update.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}