سؤال

I was thinking in a very simple Twitter-like app, I was considering support just twits and the time line.

But my head, pretty much used to relational models... cannot come up with an reasonable model in Azure tables or noSql. Basically, I was thinking in:

  • A user can add other users as friends.
  • A user can write messages (up to 200 characters).
  • Messages are always shown ordered by time, the newest the first.
  • The user page shows his last 20 messages.
  • The main page (time line) shows the last 20 messages from him and his friends.

Pretty simple :D

If I put all messages in a single table, and I put the userId as partition key... everything is easy, BUT ... I don't think that that solution scales very well. But other solutions make the time line page very complex or very unefficient, because it's not about get the latest 20 messages from every of your friends, it's about get the latest 20 from all together... and that is blowing my mind. It could be that you have a very annoying friend and the latest 20 messages are from him :D

What could be a scalable and efficient way to store this information in a Azure tables fashion?

Thanks in advance.

هل كانت مفيدة؟

المحلول

I'd say using Azure Table Storage alone isn't enough. You should use Azure Queues as well. When a message comes in it gets put in the queue. A worker takes the messages from the queue and processes them.

  1. The message goes on the Public Timeline (table keyed by timestamp)
  2. The worker gets all followers of the user who posted the message and puts a copy of the message on each of their timelines (table keyed by followerId)
  3. Of course the message also gets placed on the User's timeline. (table keyed by UserId)

It seems like this might be a wasteful method but you're optimizing for read performance with eventual consistency on the writes. Removing joins from the read side simplifies things.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top