Build an SMS Microservice using Python, Twilio and Redis Pub/Sub

A few weeks ago I needed to build a solution to send alert messages to clients of my company. The core service had access to the database, but this service had many responsibilities already and adding a new feature to send a large number of messages could overload it. So I decided to use a different approach: the core service gets the users that should receive the message from the database and builds the message content, but then sends everything to a separate service that actually sends the messages.

This new service that sends SMS messages could be used for many other applications: an alert service to notify clients of promotions, or maybe a reminder service of scheduled appointments. Since it is completely generic, it is easy to reuse it.

For this tutorial we are going to build a simple example of two Python services communicating using  Redis Pub/Sub. The main service is going to send SMS messages using  Twilio Programmable SMS. We will then build a second application that sends an SMS through it.

Tutorial Requirements

To follow this tutorial you need the following components:

  • Python 3.7 or newer. If your operating system does not provide a Python interpreter, you can go to to download an installer.
  • Redis, an open source, in-memory, NoSQL data store that we are going to use to store de messages.
  • A smartphone with an active phone number and WhatsApp installed.
  • A Twilio account. If you are new to Twilio  create a free account now. If you use  this link to open your account you will receive $10 in credit once you upgrade it.

#code #microservice

Build an SMS Microservice using Python, Twilio and Redis Pub/Sub
1.50 GEEK