Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's a good question. I suppose it's because even with Memcached taking the load off the database, we still have other issues. For example, because we're dealing with stateless connections here, it's hard to know if a client is still connected to the chat. We're polling from the client to the webservice every few seconds to 'pull' new messages and also tell the server, "Hey, I'm still alive". In order to determine if the client has left we have to monitor the polling to see if there are gaps in the poll times. Some gaps are allowed of course, because of slower connections or connection timeouts, so it gets a little tricky trying to determine if a client is still on the other end. I attribute that to HTTP, but maybe it isn't entirely to blame. If we were dealing with sockets directly, I would know the client is disconnected as soon as the connection was terminated.


To get new messages, you could simply use long polling so it becomes push instead of pull. For checking if the user is online (I'm assuming your clients are running in web browsers), you can use the onbeforeunload to send a HTTP request that the user is leaving. Of course, you still have to poll at regular intervals because the user might have put his computer to sleep which wouldn't trigger onbeforeunload but your interval can now even be as high as 60 seconds because most clients will trigger onbeforeunload.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: