Re: Help needed to built a chat feature.
Chat apps will always be "chatty", and over HTTP(s) they will always have to be client-pull, but they don't need to be particularly expensive in terms of data traffic or database calls. Ajax requests, for instance, can be HEAD requests until a new message is found, message data can be persisted in memory rather than going through the database, etc. I'm building something similar but a bit more ambitious on Google AppEngine right now, and the bandwidth and resource usage is really pretty small, thanks in large part to the memcache feature and HEAD requests. Think hard about what actually has to travel over the pipes, and what the check interval really needs to be to seem responsive -- I was able to build a live, near-real-time charity auction site on a single-processor 800MHz PIII Lotus Domino server (with a full 256MiB of RAM) that supported 1500 concurrent users and 40 simultaneous items up for bid back in 2001, and I had to use iframes/ilayers to do it since XmlHTTPRequest was an IE-only thing (and you couldn't count on MSXML being installed).
Chat can be done in a lightweight, efficient manner. But then, so can most webby things -- I consider it a failure if any web page I create causes more than five requests on load or "weighs" more than 20K all in (including cachables), but I've seen a lot of static, do-nothing pages that load Dojo, a 50K CSS file and a thousand tiny images for no reason, simply because the developer didn't think. Don't become one of those.
“Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
"It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)