Simple Messaging System Plus Broadcast

Now, after we have our Simple Messaging System with Comments, what else can happen in the messaging world ?

First, a review of the database structure :

  • message_id <- auto-increment by system
  • message_origin <- usually refers to the id in a users table
  • message_destination <- usually refers to the id in a users table
  • message_content <- the information
  • message_timestamp <- the date and time the message was sent
  • is_reply_to <- we put the previous message_id here
  • original_message_id <- we put the first message_id
  • is_private <- we put a boolean value indicating if this message can be viewed outside the original parties.

What happens next ?


A broadcast is when one person send a message to everyone in his/her network. How do we handle it ?

First, we must keep in mind that a broadcast is always the first message. It is never a reply.

The first path is to simply make the message_destination to 0, meaning it will be delivered to all. The problem is of course, it is set to deliver to everyone in the database. We cannot choose to deliver it to a specific group of people.

Now, we can simply says that the message instead of being delivered to all, it will be sent to to existing contacts of the user. But still we cannot send them over to specific group within that contact.

The alternative second path is to create a special user, which must be done in the users table. We then set the message_destination to that user_id. This way we can create special users for all in database, all in contact or specific user group. Of course, the message sender must be checked to see if he/she has priviledges to send to all.

Normally, only the application admin can send to all user in database. While all in contact is able to be sent by the user who own the contact. For specific user group, the user must be a member of that group.

The creation of the user, contact and groups are beyond the scope of this article. It is up to you for the implementation. Keep in mind how to enable the discovery of the special users.

With the special user, when a message is delivered to the special user, the system will then check who are members of that special user. The message is then delivered individually to that user. In this case it acts like a new message. You can think of it as a batch insert of messages to the database.

The third path is to create one new fields in the table, called is_broadcast_to. In this case it is similar to the second path, requiring a special user id to be put into that field.

The fourth path is creating a new boolean field called is_broadcast. It is similar to the first path, if this is true, it will be sent to everyone. The definition of everyone can be all in database or all in contact. Just like the first path.

Which path is the best ? It depends on your needs. If it is a small group where everyone in the database knows each other (a single group), then it is best to go with the first or fourth path. It is much simpler and very lightweight.

Personally, I will go with the second path. It offers a lot more flexibility. Especially since my intended application is made for multiple groups.

Naturally, after the broadcast, everything works just like a message with comments. It becomes individual conversation.

Which path will you take and why ? Do share with us by using the comments section below.