Expiring / Purging Data for Inactive Users


What’s the best way to remove (not delete) all data for a user that has not logged in for a certain amount of time (say 6 months)? Effectively that will leave all the data on the user’s device(s) but not on the server and a future login will re-upload it all.

The motivation behind it is to reduce storage requirements on the server.

The main issue of course is that this ‘purging’ a users’s data has to be atomic to ensure correctness.

Any suggestions?

Thank you

It sounds like you’d want a server-side component that keeps track of when a user last logged in. SG doesn’t do this itself, but you could do it by proxying traffic through a server that will do it, or by requiring custom authentication where the client has to call an API of your own to get a session cookie.

How to find the data owned by a user depends on your schema, of course. Presumably you’d have an owner property or something like that, which you can query for.

Purging multiple documents isn’t atomic. No operations on multiple documents are atomic, actually, since neither CBS nor SG support transactions. But since the user is by definition offline during the purge, you can have your login server deny or defer login while that user’s docs are in the middle of being purged. That way a user will never see their docs in a partially-purged state.

Thank you very much - that makes sense. Shouldn’t be too hard to implement once everything else is working.

And yes you are correct - I followed your advice on my previous question and all documents have an owner so deleting them should be trivial.

Thanks again Jens!