Part 3 of 8 · 1 min read
The channels
Providers do the last mile.
The company does not deliver messages to phones itself. It sends a request to a provider, and the provider delivers.
- iOS push. Three parts. A provider, which is the company's own server, builds a request with a device token (a unique id for the phone) and a payload (a small JSON message). It sends this to Apple's push service, APNS, which delivers it to the iOS device.
- Android push. The same flow, but with Firebase Cloud Messaging (FCM) in place of APNS.
- SMS. A third-party service such as Twilio or Nexmo, usually commercial.
- Email. Many companies use a commercial service such as Sendgrid or Mailchimp, which often gives better delivery and statistics than running their own email servers.
Being able to swap providers matters. The book points out that a provider may be missing in some markets. FCM is not available in China, for instance, where other push services are used. So the design should make each provider a plug-in with a common interface, as in the adapter idea of the low-level track.
Gathering contact details. To send, the system needs device tokens, phone numbers and email addresses. When a user installs the app or signs up, the API servers collect these and store them. A simple layout: email and phone in a user table, and tokens in a device table. One user can have several devices, so one push can go to all of them.
Check yourself: 1. What two things does a provider send to APNS? 2. Why plan for swappable providers? 3. Why is the device table separate from the user table?