Vishwa Bhat has written an excellent answer. Along with that:
Most DBs like MongoDB, Postgres, etc write data to hard disk. While Redis uses RAM. Ram is way faster than the hard disk (even on SSD) for read/write.
However, RAM is really expensive and volatile. So you can't store the entire messages in Redis. Use it as a cache layer, only frequently accessed data will be cached. If something is not present in the cache, it will be routed to a real database.
For example, in a chat between two users, who have crossed 1000 messages. Store the last 100 messages in redis, so that every time user fetches lastest messages it never hit DB.
You can also configure Redis to write a copy of everything to hard disk every x seconds, so if the server goes down and when it restarts, data from disk will be transferred to ram. You should architect it so that if redis goes down, data should be picked from real DB
I'd a similar situation, but data is not frequently changed. So instead of Redis, I used Cloudflare. Read this post: coffeencoding.com/how-i-used-cloudflare-to-reduce…