Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 602553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:50:06+00:00 2026-05-13T16:50:06+00:00

Assume we have a popular site. We need to implement mail-like messaging between users.

  • 0

Assume we have a popular site. We need to implement mail-like messaging between users.
Typical solution is to use 2 tables:

Users (user_id)

Messages (message_id, sender_id (references user_id), receiver_id (references user_id), subject, body ).

This method has 2 significant limitations

  1. All messages of all users are stored in one table leading to it’s high load and decreasing overall database performance.
  2. When someone needs to send message to several users simultaneously, the message gets copied (recipients_count) times.

The other solution uses 3 tables:

Users(user_id)

Sent_messages(sent_id, sender_id (references user_id), subject, body)

Received_messages(sent_id, receiver_id (references user_id), subject, body)

subject and body of received_messages are copied from corresponding fields of sent_messages.

This method leads to

  1. Denormalizing the database by copying information from one table to another
  2. Users can actually delete sent/received messages without removing them from the receivers/senders.
  3. Messages take approximately 2 times more space
  4. Each table is loaded approximately 2 times less.

So here go the questions:

  1. Which one of considered design is better for high load and scalability? (I think it’s the second one)
  2. Is there another database design that can handle high load? What is it? What are the limitations?

Thanks!

P.S. I understand that before getting to these scalability issues the site has to be very successful, but I want to know what to do if I need to.

UPDATE

Currently for the first versions I’ll be using design proposed by Daniel Vassallo. But if everything is OK in the future, the design will be changed to the second one. Thanks to Evert for allaying my apprehension about it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:50:07+00:00Added an answer on May 13, 2026 at 4:50 pm

    You may want to avoid copying the message body multiple times in the case where a message is sent to multiple recipients. Here is another option which you may want to consider:

    • users (user_id)

    • messages (message_id, sender_id, subject,
      body)

    • received_messages (message_id, user_id, address_mode, deleted)

    This model may be more twitter-like than email-like, but it may come with some advantages.

    The rules are that:

    • A message can only be sent by one user, referenced in the sender_id of each message.
    • Each recipient will be defined in the received_messages table. The address_mode field can define whether a message was sent to the recipient directly, or as a CC, or maybe as BCC. This field is obviously optional.
    • Deleted messages by recipients will mark the deleted flag in the received_messages table.
    • Forwarded and replied-to messages need to be recreated with a new sender_id. The message body can be then modified.

    These are some of the advantages:

    • This takes less space than the two options mentioned in the original question, especially if users will typically send messages to multiple recipients.
    • Easier caching of the messages table, since messages are never duplicated.
    • The recipient deleting a message will not erase the information that the message was sent to this user. It will simply be marked as ‘deleted’ in the received_messages table.
    • And you also get a normalized model.

    For most applications, if you use an optimistic isolation level with the above model, you should not have performance problems even if you are expecting messages to be exchanged at a rate of a few per second. If on the other hand you’re expecting hundreds or thousands of messages per second, then it may really be the case to consider other options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a class foo, and wish to use a std::map to store
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
Assume you have five products, and all of them use one or more of
Assume I have created a compiled re: x = re.compile('^\d+$') Is there a way
Assume you have some objects which have several fields they can be compared by:
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
Assume I have 10 Methods and 10 Properties. Is there a way to add
Assume I have a form class SampleClass(forms.Form): name = forms.CharField(max_length=30) age = forms.IntegerField() django_hacker
Lets assume we have this xml: <?xml version=1.0 encoding=UTF-8?> <tns:RegistryResponse status=urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure xmlns:tns=urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0 xmlns:rim=urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0> <tns:RegistryErrorList

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.