title: Realtime Scalable Chat App - which database should I choose?
body: <p>I am looking to build a scalable real-time chat app (I am just doing this for fun and out of interest so please don't ask why!) and I know that I am going to be handling the realtime messaging part through redis but I am not sure of what database to use for the following information:</p>
  <ul>
  <li>User Relationships (friends)</li>
  <li>Cold Chat History - this would only be queried in limited amounts (maybe like 50 messages) ordered by timestamp and queried in reverse (just as your messages would load in imessage or whatsapp when scrolling  to view older messages)</li>
  <li>Chat user relationship</li>
  </ul>
  <p>I know for cold chat history an RDBMS or Cassandra is probably my best bet but handling friend relationships, as well as user-to-chat relationships in an RDBMS or cassandra, is ugly. I'm not sure if it's necessary, worth it, or even &quot;right&quot; to have a graph database in my tech stack just for this relationship mapping.</p>
  <p>I was thinking of MongoDB or some other document-based storage could be a solution but querying the data seems like it would be really taxing. My thoughts were to have a chat document that has a list of users and then I would have several other documents with a list of message id's pointing to message documents. These documents would be mapped back to the chatID. I'm sure you can see though, the time and resources to query a set of messages would be quite high. Maybe I'm just underestimating the power of MongoDB as I haven't really used it. I would also be more easily able to handle the Chat User Relationship using documents as well as friendships by just storing user-ids in a list within the document.</p>
  <p>I understand there is no perfect tool for the job but I would like someone's thoughts and inputs on how to design the data storage.</p>
  <p>Thank you in advance!</p>