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.
The answer is also: definitively yes. The proof are benchmarks. A single server can handle easily more than 1000 websocket connections without problem.
WhatsApp Web internally works using WebSockets; this project does as well.
For example, when the app is open it uses Socket.io and when is closed use the APNS or GCM (depending on the device OS). Exactly this. Push Notifications are there for notifying your users when the app isn't opened. Socket.io simply opens a Web Socket while your app is active.
Real-Time Notifications (RTN) are server-to-server push notifications that provide comprehensive data about in-app purchases in real time. You can use this information to monitor purchase state changes associated with your customer's in-app purchasable items.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With