DEV Community

Onyedikachi Emmanuel Nnadi
Onyedikachi Emmanuel Nnadi

Posted on

Data Expiry & Smart Versioning: How I Solved Compliance in My App

This week I worked on two features that seemed straightforward but turned out to require more thought than expected

Dynamic consent management and smart IEP versioning for a special needs school management platform.

What I built

The system needed to record guardian consent before any assessment could be done on a child. But consent is not just a checkbox. It has to match a specific purpose, a version, and must not be expired. Getting an "active consent" wrong means potentially violating compliance. I also built IEP versioning, where the system automatically tracks whether an IEP is brand new (v1.0), a regeneration of an existing one (v1.1), or a completely fresh start (v2.0).

The problem I had to solve

The tricky part was the expiry. Consent expires after 12 months, but you cannot rely on users to manually update it. So I introduced a cron job a background task that runs automatically every night at midnight, scans every active consent in the database, and marks the expired ones. No human involvement needed.

A cron job is essentially a scheduled instruction. You tell the system "do this task at this time, on this schedule" and it handles it silently in the background. Think of it like setting an alarm that runs code instead of making noise. In backend systems, cron is commonly used for things like sending reminder emails, cleaning up old data, generating reports, and in this case, expiring records.

If you do not want to use cron, alternatives include database TTL indexes that auto-delete documents after a set time, message queues like BullMQ that let you schedule delayed jobs, or cloud-based schedulers like AWS EventBridge. Each has trade-offs depending on how much control, visibility, and scalability you need.

What I learned

The biggest lesson was about data integrity over time. A record that is correct today can become incorrect tomorrow if nothing is watching it. Cron solves that. I also learned to think carefully about timestamps specifically making sure that the time you grant consent and the time you calculate expiry from are exactly the same moment, not two separate new Date() calls milliseconds apart.

The other lesson was about version control in data. A version is not just a number. It carries meaning. 1.0 means first attempt. 1.1 means it was revisited. 2.0 means something fundamentally changed. When you model that intentionally in your system, it tells a story about what happened to the data over time.

The takeaway for you

If your application has records that should not stay valid forever, do not leave it to users to clean them up. Automate it. Write the logic once, schedule it, and let the system be honest about the state of your data at all times.

what are you building today? Drop your takes in the comment section

Top comments (0)