Android Cloud to Device Messaging (C2DM)

android.gifYesterday Google told us more about the new Android Cloud to Device Messaging (C2DM). This allows small amounts of information (up to 1024 bytes) to be pushed from your server to a specific application on given users’ phones.

The Google article briefly mentions polling vs push. As I have previously mentioned, I have found polling to work well (use not too much battery) on older (Symbian and BlackBerry) platforms and less well on Android.

However, the main problem I have found with polling is the huge load you can place on the server. With large numbers of users, it’s easy to max out a dedicated server or the free quota supplied by Google App Engine.

Push connections such as the new C2DN are usually better. However, as I previously mentioned, these are just pull connections that have a very long timeout. As the Google articles says..

"it’s also tricky to implement a good push solution, and it isn’t free as there is some overhead in maintaining the required connection"

The server-side has to accept and maintain a very large number of concurrent connections. Again, with large numbers of users, it’s easy (although less so than with polling) to max out the server. Long-lasting connections are less able to be load balanced or scaled.

Also, the problem with long running IP connections is that have to be kept going. They have to be occasionally re-freshed or re-started. Some network operators automatically terminate inactive connections very quickly and the software has to reconnect, sometimes sooner than would have been the case with a polling connection! Other times, the phone connection might fail due to the user moving in and out of GSM or WiFi coverage and again, the software has to start a new connection.

Google (and Apple) have solved these problems for developers… or more accurately hidden them behind some clever server and phone software.

The thing I like about the new Android solution is that the end-user doesn’t have to see a notification to manually start the app to receive the notification as is currently the case on iPhone. Apps can consume notifications in the background and can choose to notify the user only as and when required.

On issue yet to be clarified is…

"Google limits the number of messages a sender sends in aggregate, and the number of messages a sender sends to a specific device"

Also, Google C2DN is only available on Android 2.2 devices that limits compatibility until (or if?) a large number of existing phones get upgraded to this version.