How to avoid notifications when someone refollows?

It kind of depends on your reason for doing it. If you just want to prevent them from being able to follow/unfollow rapidly and thereby troll the alert system, you can just temporarily store them and don’t need to persist indefinitely in a DB.

If you want a more accurate representation of how long someone has been following, it’s probably best to go ahead and persist them in a DB with a created_at field instead or relying on the order of appearance.