'How to maintain the "last used Timestamp" for an entry used frequently in Relational DB?

I have a resource in the database: in my case it is Tenant and a possible number of tenants is a maximum of up to 1000. That means 1000 rows in my DB table.

These tenants are in use by many services and not necessary that a call will come to the tenant table. I need to know when a tenant is last time used. I can have a Last_Active_Timestamp field in my table, but updating that multiple times will be a performance hit to the database.

How about using a Redis cache in this case and write/push data to DB after some time interval. I can maintain a key-value pair for each tenant in a Redis cache where the value will be a timestamp and I will keep on updating the timestamp whenever that tenant is used. Finally, I can have some eviction policy to invalidate the cache after a fixed time interval like 1 hour and push all the new timestamps to DB while invalidating the DB.

Any better strategy to capture such a timestamp that is updating frequently?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source