should i use a database to store online users

i am building a chat app i am using socket io ,express js i am hesitant whether i should store the current online users in an array or store them in a database i thought of the first option because i don't wanna use alot of space from my database i am using mysql and most free options don't offer much storage these days + everytime a user logs in i would need to make a call to the database , also i am not sure if it's a good idea to store the users in an array what if i have 10k users i would have to loop over them if i want to find a specific user
3 Replies
Mcpie
Mcpie2d ago
if users on your chat app are generated by using for example a simple form just to pick a nickname then store only array. if they have to persist throughout sessions (aka "log back in") then you'll need some sort of database assuming you end up with array option, you can have it sorted and that way you'll be able to access every single one in O(logn) time by using binary search or you could use a HashSet for even faster access.
johnny  the fifth
johnny the fifthOP2d ago
@Mcpie they actually login (they have accounts)
404
4042d ago
use keydb/redis

Did you find this page helpful?