Delete With Confidence: Deciding What Your SMS Gateway Keeps and for How Long
Photo: Federal Bureau of Investigation, Public domain, via Wikimedia Commons
Every SMS gateway is a slow-motion archive. Nobody sets out to warehouse three years of message bodies; it just accumulates, because deletion feels like the one operation you can't undo. So the tables grow, the backups grow, and one day a support ticket asks you to pull the full text of a message from March 2023 — and you can, which is precisely the problem.
A retention policy is not a storage optimization exercise. It's a statement about what you're willing to be responsible for. Here's a framework that fits a US operator running a modem farm or an SMPP gateway without a compliance department.
Sort the data before you pick a number
Retention debates go sideways because people argue about 'message logs' as one thing. They're at least five:
- Operational telemetry — bind state, queue depth, throughput counters, modem signal readings. Nobody's privacy is at stake, but it's voluminous.
- Routing metadata — who submitted, to which network, when, and what happened. This is your invoice reconciliation and dispute evidence.
- Message content — bodies, UDH, concatenation parts, and anything base64'd into a TLV because someone was in a hurry.
- Delivery receipts — the DLR trail, which proves the handset accepted it (or didn't).
- Consent and opt-out records — STOP replies, opt-in timestamps, campaign associations. This is the one category you keep longest, because it's your defense if a complaint lands.
Give each class its own window. One number for everything guarantees you either delete too much or keep too much.
Windows you can actually defend
Starting points that hold up in practice:
- Telemetry: 7 to 14 days at full resolution, 90 days rolled into hourly aggregates. You will never debug a 2024 queue spike from raw counters.
- Routing metadata: 90 days is the floor, 13 months is comfortable. Your carrier contracts and rate dispute windows should set this, not vibes.
- Message content: 24 to 72 hours by default. Long enough to debug a delivery failure while the ticket is open, short enough that a breach doesn't become a content breach.
- DLRs: 30 to 90 days, long enough to reconcile against invoices and short enough to keep the table sane.
- Consent records: indefinite, or as long as your legal counsel says. These are proof, not logs.
Write the reasoning next to each number. An auditor doesn't need you to be conservative, they need you to be consistent.
Redact at ingest, not at export
If content has to live in your system for 72 hours, it should live there in a form that's useless if the bucket leaks. Two moves cover most of it:
- Hash the MSISDN with a keyed HMAC rather than a plain digest. You can still correlate a number to its history without storing the number. Keep the last four digits in a separate column if support genuinely needs to confirm identity.
- Scrub bodies on write. Detect one-time-code patterns and replace them. Store length, encoding, character count, and a hash of the body — enough to prove two messages were identical, not enough to read them.
Do the redaction in the ingest path, not in a nightly job. A nightly job means the unredacted version existed somewhere for hours, and it means one failed cron run silently changes your policy.
Access controls that survive an audit
Retention is only half the story; the other half is who can read what's left.
- Support sees metadata and the last four digits. No bodies, no full numbers.
- Engineering gets a time-boxed break-glass view of content, granted by ticket, expiring automatically.
- Analytics queries hit a read-only replica with the content columns physically absent, not just permission-denied.
- No shared database credentials. Every query that touches message tables should be attributable to a person.
Then log the reads, not just the writes. When someone asks whether a customer's message content was accessed, the answer should come from a table, not a memory.
Make deletion the default
Manual purges never happen. Partition by day, drop partitions on a schedule, and let the job be boring. For anything stored encrypted at rest, key destruction is a legitimate deletion method — the ciphertext remains, the plaintext is gone, and it's fast enough to run on a weekend.
Two guardrails so the drop job never becomes the incident:
- Legal hold is checked before every drop, and the list of people who can invoke a hold is short and written down.
- Deletion itself is logged — partition name, row count, job identity, timestamp — so you can prove a record was removed on purpose rather than lost.
Test the delete
Once a quarter, insert a canary record with an obvious marker, wait out the retention window, and confirm it's gone. Restore a backup and verify the canary isn't resurrected by a restore that predates the purge. That last part catches the most embarrassing failure mode: a policy that's followed in the primary database and quietly ignored in the backup chain.
The point of all this isn't to keep less data for its own sake. It's to be able to say, with a straight face, exactly what you hold, why, for how long, and who can see it. That sentence is worth more than any retention number you pick.