facebook / akd

An implementation of an auditable key directory
Apache License 2.0
247 stars 36 forks source link

Update tombstone API to minimize DB ops #429

Closed afterdusk closed 8 months ago

afterdusk commented 8 months ago

Current

Our current tombstoning API tombstone_value_states accepts a list of ValueState keys that tombstoning should be performed for. This means that the client flow will, more often than not, involve:

  1. looking up all ValueState objects for a given user in DB
  2. figuring out which objects should be tombstoned based on their epochs (relative to the current epoch)
  3. passing the keys of said objects to the tombstone API

Internally, the tombstone API then does another lookup of ValueState objects with the keys passed, modifies the objects to "tombstone" them, then another write to commit the now-tombstoned objects.

Proposed

We can cut out the DB lookup pre-API call by having the API take in an epoch and a username, then tombstoning all ValueState objects for the user with an epoch less than or equal to the passed epoch. Clients will not need any knowledge of what ValueState objects a user has, and just need to inform the API which epoch to stop tombstoning at.

In addition, before we write the tombstoned records, we should filter out any objects that are already tombstoned, to avoid unnecessary writes.