Instagram clone | How to handle stories being visible only for 24h?
Title says it all. How would you handle Instagram stories being visible only 24h after being posted?
I'm working with mongooose. I found there is an
expires
option available in second parameter of mongoose.Schema()
:
But I'm not sure what happens after it expires? I don't want it to get deleted. I still want to have the story in my DB (so user can add it to highlights, view it in his archive etc.), just not visible to users anymore.
I was also thinking of just using createdAt
which is coming from timestamps: true
and then somehow filter stories that are posted within 24h and display them to the user. Not really sure if that's the best way to go.
Any ideas/solutions/recommendations?3 Replies
The easiest way is definitely filtering on createdAt or a separate publishedAt column
At Instagram scale it might be something different, but you really, really don't need to worry about that, filtering on those columns will work up to millions of rows
imma keep it real, they prolly aren't using mongo at instagram
and yeah I'd just go for a timestamp and display stories within a certain timeframe
as far as the "expires" field, I'd assume that's mongoose setting a TTL (time-to-live) index which deletes your documents after the specified time, so yes, it would get deleted
Alright, thank you both for useful info!