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 6988027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:01:00+00:00 2026-05-27T19:01:00+00:00

For my university project, I’m developing a dynamic live chat website with rooms, user

  • 0

For my university project, I’m developing a dynamic live chat website with rooms, user registration, etc. I’ve got the entire system planned out bar one aspect. The rooms.

A room is created by a user who is then an operator of that room. Users can join the room and talk within it. The system has to be scalable, accounting for hundreds of thousands if not millions of messages being sent a day.

I was going to create on table in my database called messages, and have fields like this:

| r_id | u_id | message | timestamp |

r_id and u_id would be foreign keys to the room ID and user ID respectively. This would mean I would insert a new record when a user sends a message, and periodically run a SELECT statement for every client (say every 3 seconds or so) to get the recent messages. But because the table will be huge, running these statements might create a lot of overhead and take a long time.

Another way of implementing this would be to create a new database table for every room. Say a user creates 3 rooms called General, Programming and Gaming. The database tables would be room_general, room_programming, and room_gaming, each with fields like:

| u_id | message | timestamp |

This would drastically cut down on the amount of queries for each table, but might introduce problems when I come to program it.

So, what is the best way to do this?

I’m using MySQL with PHP and AJAX.

  • 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-27T19:01:01+00:00Added an answer on May 27, 2026 at 7:01 pm

    It is bad idea to create a table per room. Hard to implement and hard to support.

    Dont worry about performance of selects because they will be wery simple:

    SELECT * FROM messages WHERE r_id=X ORDER BY timestamp DESC LIMIT X,Y
    

    Just make sure your (r_id, timestamp) indexed together in this order to make this select using index:

    ALTER TABLE `messages` ADD KEY `IN_messages_room_time` (`r_id`, `timestamp`);
    

    If you will still have problems with performance (probably you will not), just add a 1-3 seconds inmemory cache (using memcache) and fetch a messages from DB one time per 1-3 seconds.

    Also look at the Apollo Clark’s answer: https://stackoverflow.com/a/8673165/436932 to prevent storing huge amount of unneccessary old messages: you can just put it in to the MYISAM table archive or simply delete.

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

Sidebar

Related Questions

I'm developing a small POS for a university project. I have a form which
I've got a university project to create a site using a framework given to
I'm developing an MVC3 application for a university project. I am hoping to use
I'm developing an online survey application for my University project. I managed to save
As part of a university project I'm developing a web application in PHP and
i have to design a user account/profile tables for a university project. The basic
i've got a university project where i need to develop a peer to peer
im doing a simple website for a university project, and one of the requirements
I am developing a web application for my university project this summer and I
I'm trying to get a fake movie website going for a University project. But

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.