My (SMS | email) provider is down!?

David Brown
Aug 24, 2017 · 2 min read

By David Brown

This post originally appeared on Notif.me blog.

It might (hopefully) be occasional, but it happens. I’ve seen providers not responding because:

  • They were doing scheduled maintenance
  • They blocked the account because of a spike the day before or because the credit card was refused and nobody read the reminders
  • They were simply down

Well, keep calm and use Notif.me!

What is Notif.me?

Notif.me is an open source Node.js library to send all kinds of transactional notifications. It allows you to use multiple providers and a fallback strategy out of the box.

Not developing in Node.js? You can still run it in a micro-service (see notifme-sdk-queue-rabbitmq to get an example).

Use a fallback provider

If you’re using only one provider, it’s about time to open a second account and use it in case the first one fails. We wanted to make that very easy with notifme-sdk:

$ yarn add notifme-sdk------------------------------------------------------------import NotifmeSdk from 'notifme-sdk'new NotifmeSdk({
channels: {
sms: {
// Use Nexmo and fallback to Twilio in case of failure
multiProviderStrategy: 'fallback',
providers: [{
type: 'nexmo',
apiKey: 'xxxxx',
apiSecret: 'xxxxx'
}, {
type: 'twilio',
accountSid: 'xxxxx',
authToken: 'xxxxx'
}]
}
}
})
notifmeSdk.send({
sms: {
from: 'Notifme',
to: '+15000000001',
text: 'Hello, how are you?'
}
})

That should cover almost any case you will encounter.

Going even further

If all your notifications are critical for your business, here are two more things you need to consider:

1. Handle fallback failure

This is for the slight possibility of having all your providers failing:

const request = {
sms: {from: 'Notifme', to: '+15000000001', text: 'Hello'}
}
notifmeSdk.send(request).then((result) => {
if (result.status === 'error') {
/*
* Here is a (non-exhaustive) list of what you can do:
* 1. Try another channel:
* notifmeSdk.send({email: {...}})
* 2. Construct the new request with the failing channels
* and enqueue it to a delayed queue to retry it later.
*/
}
})

2. Integrating your providers’ webhooks

You should also handle error events happening after a provider accepted your request. For example if you send an email and get a soft bounce because your user’s inbox is full, you can try to send a web push notification or a SMS instead.

This is not possible yet with Notif.me SDK but this is definitely something we’d like to work on.

Conclusion

If you like this project, you can star our GitHub repository and stay tuned for the next episode :)

)
David Brown

Written by

Developer & co-founder of https://www.notif.me (transactional notification API for developers)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade