Skip to content

Bug: document autosave fires on every keystroke with no debounce, causes Supabase write storm #1051

Description

@anshul23102

Bug Report: Autosave on Every Keystroke Exceeds Supabase Free-Tier Write Limits

Description

The document editor triggers an autosave to Supabase on every onChange event
from the text editor component : effectively on every keystroke. A user typing
at 60 WPM generates approximately 300 keystrokes per minute, each triggering
a separate Supabase UPDATE call. The Supabase free tier allows 500MB database
egress and 2 million rows read/written per month. A single active user typing
for one hour exhausts a significant fraction of the monthly write quota.

Steps to Reproduce

  1. Open the Supabase dashboard and navigate to Database > Logs.
  2. Start typing in the Draftdeckai document editor.
  3. Observe a new UPDATE documents SET ... query for each keystroke.
  4. After 1 minute of typing, check that ~300 write operations have been logged.

Root Cause

The onChange callback calls supabase.from('documents').update(...) directly
without debouncing. No minimum interval is enforced between saves.

Impact

Heavy users exhaust the Supabase free-tier write quota within days, causing
the database to return errors and making the editor non-functional until the
quota resets.

Proposed Fix

Debounce the autosave call with a 2-second delay:

const debouncedSave = useMemo(
  () => debounce(async (content: string) => {
    await supabase.from("documents").update({ content }).eq("id", docId);
  }, 2000),
  [docId]
);

// In editor onChange:
onChange={(value) => {
  setContent(value);
  debouncedSave(value);
}}

Also add a visual "Saving..." indicator that clears to "Saved" after the
debounced call completes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions