I am looking for some advice. I will be working on user follow system (like twitter) for my site. I expect it to have a large number of users using this system.
So, I would like to know what is better to use to store all the data for this system. Should I use user meta, custom taxonomies or should I work directly with the database?
I was thinking about creating some user meta, so each user has meta for followers and a meta for following, each would be filled with users’ ids. Is there a better way from the stanpoint of scalability?
Thanks!
In the case where you want to store each piece of data as a unique entry (row) in the database, then a custom table, as you’ve already done, is a perfectly fine solution.
On the other hand…
You could use the usermeta table to do the exact same thing, storing multiple meta keys with the same name as unique entries,
Entries in the usermeta table would look like the following:
As you can see in the example above, the fourth entry in the usermeta table is for a piece of completely unrelated metadata, so that is what you will contend with, all kinds of data mixed into the one table. Overtime, if this table contains a lot of extra meta information in addition to your follow-data then it can possibly effect the performance of your queries.
Personally I would create a custom table and only store user_id and follower_id (possibly the follower_username too).
Storing the username along with the ID is optional but useful.
Then I’d also store a serialized value of all people following a user against the individual user within usermeta table which you can do periodically via wp_cron. If you need to show a given user who is following them, you can retrieve an individual usermeta meta_key, unserialize the data and present it accordingly.
If you happen to also store the username of the follower, the serialized data for a user will also contain the username which will avoid you needing to run a lookup on the returned ID if all you need to show is a username and possibly a link to the user.
The ID is returned if you need to perform any additional data retrieval and manipulation which you can do from the username alone but, an ID is always handy and for me, it’s preferred.
Of course all of this is highly generalized because it really depends on your extended use case as to what you may do.