GDPR Data Deletion in Multi-Tenant SaaS: A Purge Pipeline

Thesis: in a multi-tenant SaaS, "delete my data" is not a SQL statement. It's a pipeline that has to reach every place a person's data landed: the primary database, file storage, search indexes, caches, logs, analytics, third-party processors and backups. If you don't design that pipeline on purpose, you end up with a delete button that removes a row and leaves copies everywhere else.
Quick answer: GDPR data deletion in multi-tenant SaaS. Build a deletion pipeline, not a delete query: register every data store, check legal holds and retention rules, anonymize records you must keep, hard-delete the rest with idempotent jobs per store, expire backups on a fixed schedule, and log a deletion receipt you can re-apply after any restore.
I wrote this with help from AI tools and checked every code sample and claim myself. Disclosure: I run Loop Origin, a software studio that builds custom SaaS platforms.
Two different requests that teams mix up
Most SaaS products face two kinds of deletion, and they need different code paths:
- Data subject erasure. One person (an end user, or a contact inside a customer's account) asks to be erased under GDPR Article 17. The tenant stays; that person's personal data goes.
- Tenant offboarding. A customer cancels and their contract says data is deleted after a grace period. Everything that tenant owns goes, except what you must keep for your own legal duties, such as invoices.
GDPR gives you one month to respond to an erasure request, extendable by two further months for complex cases (Article 12(3)). Article 19 also expects you to tell the recipients you shared the data with. That second part is what most implementations forget: the email provider, the CRM sync, the analytics tool.
Step 1: a data map that code can read
You can't delete what you can't find. Before any pipeline, keep a registry of every store that can hold personal data, owned by the team that owns the store. In Laravel I keep it as code, so a new table or integration can't ship without an entry:
// config/erasure.php return [ 'stores' => [ App\Erasure\UsersEraser::class, // users, profiles, sessions App\Erasure\TicketsEraser::class, // support tickets and replies App\Erasure\UploadsEraser::class, // S3 objects under tenant/user prefixes App\Erasure\SearchIndexEraser::class, // Meilisearch / Elastic documents App\Erasure\MailProviderEraser::class, // suppression + contact delete via API App\Erasure\AnalyticsEraser::class, // product analytics user delete API ], ]; Each eraser implements one small interface:
interface Eraser { public function name(): string; /** Must be safe to run twice. Returns a count for the receipt. */ public function erase(ErasureRequest $request): int; } A CI check that fails when a migration adds a column named like email, phone or ip_address without a matching eraser update is cheap and catches most drift.
Step 2: decide delete, anonymize or keep
Not every record can simply disappear. An invoice belongs to your accounting records; an audit log row may be needed to prove who changed a permission. The trick is to separate the personal data from the business fact.
| Technique | What happens | Use it for | Watch out for |
|---|---|---|---|
| Hard delete | Row or object removed | Profiles, uploads, messages, sessions | Foreign keys, cached copies, search index |
| Anonymize | Personal fields replaced, row kept | Orders, invoices, metrics rows | Free-text fields that still contain names |
| Pseudonymize | ID replaced with a random token | Audit trails, event history | Keep the mapping out of reach or delete it |
| Crypto-shredding | Per-tenant or per-user key destroyed | Encrypted blobs, archives, backups | Key management must be solid from day one |
| Retention expiry | Data ages out on a schedule | Logs, backups, raw events | Schedule must be documented and enforced |
If you already keep an append-only audit log, as in Immutable Audit Trails in Postgres for SaaS, don't break immutability to erase someone. Store the actor as an opaque ID from day one and erase the mapping table instead.
Step 3: the pipeline itself
The request flows through five states: received, verified, on hold or approved, erasing, completed. Here is the core of the orchestration with Laravel's job batching:
public function handle(ErasureRequest $request): void { if ($request->tenant->hasLegalHold() || $request->subject->hasLegalHold()) { $request->markOnHold('legal hold'); // a human reviews, nothing is deleted return; } $request->subject->update(['erasure_pending_at' => now()]); // blocks login + new writes $jobs = collect(config('erasure.stores')) ->map(fn ($eraser) => new RunEraser($request->id, $eraser)); Bus::batch($jobs->all()) ->allowFailures() ->then(fn () => CompleteErasure::dispatch($request->id)) ->catch(fn () => $request->markNeedsAttention()) ->name("erasure:{$request->id}") ->dispatch(); } Three details make this survive production:
- Idempotent erasers. Each one records its count in an
erasure_stepstable and can be re-run safely after a crash or a third-party timeout. - Freeze before delete. Marking the subject as pending stops a background sync from re-creating the data you just removed, the classic "deleted user came back" bug.
- Anonymize SQL that covers free text. Replacing the email column isn't enough when a ticket body says "Hi, I'm Sara from…".
UPDATE orders SET customer_name = 'Erased customer', customer_email = concat('erased+', id, '@invalid.example'), shipping_address = NULL, notes = NULL WHERE tenant_id = :tenant AND customer_id = :subject; Step 4: backups, the part everyone asks about
You usually can't edit a backup in place, and you shouldn't try. The workable approach is:
- Keep backups on a fixed, documented retention window, for example 35 days of point-in-time recovery. I covered the settings in SaaS Backup & Disaster Recovery: RPO, RTO and PITR.
- Say in your privacy notice that deleted data leaves backups when they expire.
- Keep a deletion log with IDs only (no personal data) and replay it automatically after any restore, so a restored database doesn't bring erased people back.
- For long-term archives, encrypt per tenant and destroy the key at offboarding. That is crypto-shredding: the bytes stay, but nobody can read them.
Failure modes I see in real codebases
- Search index ghosts. The row is gone, but the person still appears in global search because the index was never told.
- Orphaned S3 objects. Uploads were keyed by random UUIDs with no tenant prefix, so nobody can list "everything for this tenant".
- Logs full of request bodies. Debug logging captured emails and phone numbers; now your log retention is your erasure deadline.
- Processor drift. Marketing added a new tool through a no-code integration, and it's not in the registry.
- Cascades that delete invoices. An
ON DELETE CASCADEfrom users to orders quietly removed records you were required to keep.
Build vs buy
| Option | Fits when | Trade-off |
|---|---|---|
| Built-in pipeline (as above) | You own the stack and have more than a few data stores | Engineering time up front; full control and evidence |
| Privacy platform (DSAR tooling) | Many SaaS processors, legal team wants a portal | Still needs connectors into your own database |
| Manual runbook | Very early product, few requests | Doesn't scale; easy to miss a store |
Even with a vendor tool, the erasers for your own database, files and index are code you'll write. The vendor handles intake and tracking.
Implementation checklist
- [ ] Data map lives in code, reviewed in CI
- [ ] Separate flows for person erasure and tenant offboarding
- [ ] Legal-hold and retention checks before any delete
- [ ] Anonymize business records, hard-delete the rest
- [ ] Actors in audit logs stored as opaque IDs
- [ ] Idempotent erasers with per-step status
- [ ] Subject frozen before deletion starts
- [ ] Search, cache, files and processors covered
- [ ] Backup retention documented; deletion log replayed on restore
- [ ] Receipt stored with counts per store, no personal data
If you are planning this for your own platform, our custom web application development page explains how we scope this kind of work.
FAQs
Do I have to delete data from backups immediately?
Regulators generally accept that backups can't be edited in place, as long as the data is beyond normal use, the retention window is fixed and documented, and erased records aren't restored into live systems. Get legal advice for your specific case.
Can I keep invoices after a GDPR erasure request?
Yes, where you have a legal obligation to keep accounting records, Article 17(3) allows it. Keep only what the obligation needs and remove the rest of the person's data from that context.
Is anonymized data still personal data?
Only if it can still be linked back to the person. Replacing an email but leaving a unique username, address or free-text note means the record is pseudonymized, not anonymized, and GDPR still applies to it.
How do I delete data from third-party tools?
Treat each processor as an eraser: call its delete or suppression API, record the response, and retry with backoff. If a tool has no API, add a manual task to the request and track it to completion.
What is crypto-shredding?
Encrypting data with a key per tenant or user, then destroying that key to make the data unreadable. It works well for archives and object storage, but only if key management was designed in from the start.
How long should tenant offboarding take?
That's a contract and policy decision. Many SaaS products give a grace period for export, then run the pipeline. Whatever you choose, write it down, automate it and keep the receipt.
Bottom line
Erasure is a feature with a data map, a state machine and evidence, not a button. Build it once, cover every store and processor, and deletion requests become routine work.
Follow & Connect
- LinkedIn: Loop Origin
- X: Muhammad Ali Mughal (@AliMughal887)
- GitHub: Loop Origin (@LoopOrigin)
Watch on YouTube: Resume Boost AI · PixelValut · Daily AI News By Ali
原文:https://www.a8q9.cn/en/article/gdpr-data-deletion-in-multi-tenant-saas-a-purge-pipeline-49e098.html