Skip to content

How to delete user data for GDPR (right to erasure)

Updated 8 November 2026 · 7 min read

“Delete my account” looks like one SQL statement. Under GDPR it is usually more work, because a user’s data spreads into logs, analytics tools, email providers, file storage and backups. This guide covers what the right to erasure asks for and how to build a deletion flow that holds up.

This is our own reading of the GDPR for developers, not legal advice.

What the law asks

Article 17 gives people the right to have their personal data erased when, among other reasons, it’s no longer needed, they withdraw consent, or they object and you have no overriding reason to keep it. There are exceptions, for example data you must keep by law, such as invoices for tax.

Article 12(3) says you must answer a request without undue delay and within one month, extendable by two more months for complex cases if you tell the person why. Article 19 says you should tell the companies you shared the data with, unless that’s impossible or takes disproportionate effort.

Step 1: Map where the data goes

Before writing deletion code, list every place a user’s data ends up. For a typical web app:

Place Examples
Main database users, profiles, orders, comments, uploaded files
File storage avatars and documents in S3, Supabase Storage, Cloudflare R2
Logs application logs, error trackers (Sentry), request logs
Analytics PostHog, Mixpanel, Google Analytics, product events
Email and messaging your email provider’s contact lists, support desk, CRM
Payments Stripe customer records
Backups database snapshots
Search and caches search indexes, Redis

The personal data in logs guide helps keep the logs row short.

Step 2: Decide delete or anonymise

Some rows must stay: an order that’s needed for accounting, a message another user still sees. For those, remove what identifies the person and keep the rest.

-- Delete what has no reason to stay
DELETE FROM sessions WHERE user_id = $1;
DELETE FROM profiles WHERE user_id = $1;

-- Keep the order for tax records, without the person
UPDATE orders SET email = NULL, name = NULL, address = NULL WHERE user_id = $1;

Be careful with “anonymised”: if the remaining data can still be linked back to the person, it’s still personal data.

Step 3: Build one deletion function

Put the whole flow in one place, run it in a transaction for the database part, and record that it happened without keeping the data itself:

export async function deleteUser(userId: string) {
  await db.transaction(async (tx) => {
    await tx.query("DELETE FROM sessions WHERE user_id = $1", [userId]);
    await tx.query("DELETE FROM profiles WHERE user_id = $1", [userId]);
    await tx.query("UPDATE orders SET email = NULL, name = NULL, address = NULL WHERE user_id = $1", [userId]);
    await tx.query("DELETE FROM users WHERE id = $1", [userId]);
  });

  // Outside the database: each call should be safe to retry
  await storage.deleteFolder(`avatars/${userId}`);
  await analytics.deletePerson(userId);       // most analytics tools have a deletion API
  await email.removeContact(userId);
  await stripe.customers.del(stripeIdFor(userId));

  await audit.log({ event: "user_deleted", userId, at: new Date() }); // the id and time, not the data
}

If one external call fails, retry it from a queue rather than leaving the deletion half done. Keep a list of pending deletions until every step has succeeded.

Step 4: Backups

You usually can’t edit old database snapshots. A common, defensible approach:

  • Keep backups only as long as you need them, for example 30 days.
  • Keep a list of deleted user IDs, and if you ever restore a backup, run the deletions again before the restored data is used.
  • Write down this approach, so you can explain it if asked.

Step 5: Test it

Create a test user, use every feature that stores data, then run the deletion and check each place in the table from step 1. Put that check in your tests, so a new feature that stores data somewhere new doesn’t quietly break erasure.

What a reviewer may ask for

  • the data map from step 1
  • the deletion code or runbook
  • how long backups are kept and how restores handle deleted users
  • a record of requests received and when they were completed

What Lintsure checks

Erasure is mostly design and process, so Lintsure lists it under work outside code. Its rules help shrink the problem by catching personal data where it’s hard to delete later:

Check your own code

Lintsure runs these checks on your machine and never uploads your code.

npx lintsure scan

This guide is our own reading of public texts, written for software teams. It is not legal advice and it doesn't cover your whole obligation, only the parts code can show. Ask a qualified person before any audit or decision. Disclaimer