{"name":"design-doc-template","title":"Software design document template","description":"A software design document template in Markdown with goals, non-goals, proposed design, alternatives, security, rollout and open questions, on a real feature.","category":"specs","updated":"2026-11-30","url":"https://sniptide.com/templates/design-doc-template","files":[{"name":"docs/design/scheduled-exports.md","language":"markdown","content":"# Design: Scheduled exports\n\n- Author: Platform team\n- Reviewers: Backend, Security\n- Status: In review\n- Last updated: 2026-11-30\n\n## Summary\n\nWorkspace owners can schedule a CSV export of their reports to run daily or weekly and arrive by\nemail or in an S3 bucket they own. This document proposes a scheduler table, a worker job and a\ndelivery step, and estimates three weeks for one engineer.\n\n## Background\n\nCustomers export reports by hand from the Reports page today. Twelve of our 40 largest accounts\nasked for automatic exports last quarter, and four wrote scripts against our API to do it, which\ncauses most of our API rate-limit errors.\n\n## Goals\n\n- An owner can create, pause and delete a schedule for any saved report.\n- Exports arrive within 15 minutes of the scheduled time.\n- A failed delivery is retried and the owner is told when it gives up.\n\n## Non-goals\n\n- Formats other than CSV. XLSX can follow once this ships.\n- Schedules more frequent than daily.\n- Delivery to destinations other than email and S3.\n\n## Proposed design\n\n### Data model\n\nA new `export_schedules` table stores the report, the cadence (`daily` or `weekly` with a weekday),\nthe time and time zone, the destination and `next_run_at`. Destinations store an S3 bucket and\nrole ARN, never access keys.\n\n### Scheduling\n\nA worker runs every minute, claims schedules with `next_run_at <= now()` using `FOR UPDATE SKIP\nLOCKED`, enqueues one export job per schedule and advances `next_run_at`. Computing the next run in\nthe schedule's time zone keeps exports at the same local time across daylight saving changes.\n\n### Export and delivery\n\nThe export job reuses the existing CSV generator. Files under 10 MB are attached to the email.\nLarger files are uploaded to our storage and emailed as a link that expires after 7 days. S3\ndelivery assumes the customer's role with an external ID and uploads with `PutObject`.\n\n### Failure handling\n\nDelivery retries three times with exponential backoff. After the last failure the schedule is\npaused and the owner gets an email and an in-app notification that says what failed.\n\n## Alternatives considered\n\n- **A cron service per schedule** (such as EventBridge Scheduler). Precise timing, but adds a\n  cloud dependency that self-hosted customers don't have.\n- **Let customers keep scripting the API.** No work for us, but rate-limit errors keep growing.\n\n## Security and privacy\n\nExports contain customer financial data. Email links are signed and single-workspace. S3 delivery\nuses role assumption with an external ID, so we hold no customer credentials. Every run is written\nto the audit log.\n\n## Rollout\n\n1. Ship behind a feature flag to five accounts that asked for it.\n2. Watch delivery success rate and export duration for two weeks.\n3. Enable for all paid plans and announce in the changelog.\n\n## Open questions\n\n- Do we count scheduled exports against the API rate limit?\n- Should owners be able to send to more than one destination per schedule?\n"}]}