Structure for storing followers and following

I’m trying to implement a structure to keep track of a user followers and people following him, I will later use this values to filter out all the people that are not connected with this user in a search, connected means that he either follows them or they follow him. I came up with the idea of adding an array of IDs for each one of those properties, and I would then update them based on the action of a user following someone, that action would trigger an update to the algolia index that would either remove or add a new user to such array.

My only issue with this approach is because we can easily run into some concurrency issues where some user is being removed from the array, but another added and one of those updates will overwrite the other if they happen in a small-time space.

I went through the docs about concurrency and versioning, but will versioning solves a lot of problems it won’t solve mine since I can’t discard any changes, if someone is followed/unfollowed the array has to always be updated with those values, per action.

Any idea on how to structure such data and how to handle the concurrency issue?