Noms

Menu

Auto Link Deletion in shortCuts

Dated - 5 Feb 2024
 

This weekend, automatic link deletion feature was introduced in shortCuts [ref commit - 8e640e0, app version - 1.1.4-b]. While designing the architecture of said service I had two options, either use Postgres cron job [an extension] to schedule deletion or design on my own, since shortCuts has MongoDB to measure analytics prior was not a good option.

The above image is early stage design, when request comes from "/api/link" endpoint with some deletion time referred in request body. Every link has is_alive column set to true, pointing that link can be served.


After the link is created, Cron utility function schedules a job to delete the record. Scheduler then calls another function responsible for actual deletion of link in main Postgres database and MongoDB when appropriate time comes. Record in MongoDB are permanently deleted, on the other hand a record in main database still exists with "is_alive" attribute set to false.


So Where does the link go?
Link stays in Postgres DB for a week, When a request is made shortCuts first checks the "is_alive" condition before serving a long URL, if the condition is false it will simply display 404 error else return response. Deletion happens every week, done by another job scheduled to run every week after weekly backup has been taken care of [another topic to discuss here].


Another important feature to add following this is delaying link deletion by update endpoint. If you have any suggestions to improve above architecture mail me at[email protected]