Search code examples
asp.netsql-serverajaxchatpolling

Asp.net chat application using database for message queue


I have developed a chat web application which uses a SqlServer database for exchanging messages.

All clients poll every x seconds to check for new messages.

It is obvious that this approach consumes many resources, and I was wondering if there is a "cheaper" way of doing that.

I use the same approach for "presence": checking who is on.


Solution

  • For something like a real-time chat app, I'd recommend a distributed cache with a SQL backing. I happen to like memcached with the Enyim .NET provider, so I'd do something like the following:

    1. User posts message
    2. System writes message to database
    3. System writes message to cache
    4. All users poll cache periodically for new messages

    The database backing allows you to preload the cache in the event the cache is cleared or the application restarts, but the functional bits rely on in-memory cache, rather than polling the database.