Iphone – Push Notification vs. Web Sockets for implementing a real-time chat app

apple-push-notificationsiphonemessagingpush-notification

I'm looking into building a real-time chat app for iPhone (but this question applies to Android and other devices as well) Basically I want the app to receive realtime messages while it's open as well as while it's closed, just like the iPhone's own "Message" app.

When it's closed I can use the native push notification services like APNS, and when the app is open, I can run my own websockets server or use 3rd party providers like PubNub or Pusher, which is what I've been doing actually.

Then I wondered: Why can't I completely rely on APNS for the real-time messaging, both while the app is open and while it's closed? This feels like a much cleaner solution since it's driven by one push server. Could someone enlighten me? Thanks.

Best Answer

APNS is not 100% reliable. It is in most cases, but not 100%. It is also not as quick as a dedicated service you would offer. Sometimes, push messages take upwards of one minute to arrive. You need to consider these and take it into consideration in any design you come up with. If you can live with these limitations, you can indeed rely on the APNS to update your client. Moreover, with iOS7, an app could wake up in the background, retrieve data and update its UI so that user is presented with an up-to-date app.

While speaking about performance, to be able to handle a multitude of open connections and service them concurrently is not as simple as it sounds, so depending on your resources, you may not be able to provide a better service uptime than Apple's APNS, so the limitations above, while true, are not necessarily as bad as they may sound.

I think best would be, since you need to implement push support anyway, to implement APNS only, and see if this satisfies you and your clients. Remember that the sandbox (debug) APNS servers are slower than normal production APNS servers, so test with release versions to see the real performance implications of going APNS-only. If down the road you notice that the provided service is not enough, you can only implement further services.

Related Topic