When you're ready to scale messaging for your application, you should keep a few best practices and key questions in mind as you build and work with Twilio.
This guide presents common use cases and location-specific complexities that can affect your messaging application. Knowing how, where, and to whom you plan to send messages will help you avoid some common pitfalls while scaling.
Perhaps you built out your messaging application's proof-of-concept by sending messages from a single long code phone number. However, as you scale, your application may require different types of senders, such as short codes, Alpha Sender ID, WhatsApp senders, and phone numbers. You will also want to use features such Advanced Opt-Out for compliance management, and Smart Encoding to catch those segment-gobbling Unicode symbols.
Intrigued? Check out the full list of Messaging Service features.
You can think of a Messaging Service as a container to hold all of your sender IDs and to manage the configuration affecting the delivery of your messages. For example, you could put your short code and local numbers in one Messaging Service sender pool and configure them to point to the same webhook URL to respond to incoming messages. You could also define the same set of opt-out (Stop) words per country for all of the senders in your sender pool using the Messaging Service Advanced Opt-Out feature.
When sending messages from a Messaging Service, you can set the From parameter to your Messaging Service SID, instead of a specific phone number. This not only provides intelligent routing for the senders in your Sender Pool, but also gives you access to the various Messaging Service Features, like Advanced Opt-Out, Sticky Sender, Shortcode Reroute, Smart Encoding and more.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createMessage() {11const message = await client.messages.create({12body: "Do you know what time it is? It must be party time!",13messagingServiceSid: "MG9752274e9e519418a7406176694466fa",14to: "+15558675310",15});1617console.log(message.body);18}1920createMessage();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"api_version": "2010-04-01",4"body": "Do you know what time it is? It must be party time!",5"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",6"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",7"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",8"direction": "outbound-api",9"error_code": null,10"error_message": null,11"from": "+14155552345",12"num_media": "0",13"num_segments": "1",14"price": null,15"price_unit": null,16"messaging_service_sid": "MG9752274e9e519418a7406176694466fa",17"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",18"status": "queued",19"subresource_uris": {20"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"21},22"tags": {23"campaign_name": "Spring Sale 2022",24"message_type": "cart_abandoned"25},26"to": "+15558675310",27"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"28}
If your messaging use case is Two-Factor Authentication (2FA) codes, you'll want to use Authy or Verify, rather than Programmable Messaging.
Depending on what you build with Twilio Programmable Messaging, you may use different types of message senders as the primary way that customers interact with your application. There are different sender types to choose from:
The answers to the following questions will determine what kind(s) of senders you should select and include in your Messaging Service's Sender Pool.
Consider your use case: do you need your recipients to be able to reply to your messages? If so, that is called "two-way messaging."
More modern messaging channels like WhatsApp always support two-way messaging. With SMS, however, two-way messaging is not always supported; you'll need to make sure that you use the correct number type (if available), or consider an alternative such as WhatsApp.
Check out our two-way SMS FAQ for more information, or read about WhatsApp.
If you only need to send one-way messages to your recipients, you generally have more options for sender types. However, you still should consider the countries to which you are sending and your use case - read on for details.
Regulations vary by country, so make sure to check out country-specific guidelines for the countries in which you plan to send SMS.
Not all sender types work in every country, so you should determine in advance where you want to send messages:
In the United States and Canada, you can send messages from a few types of numbers.
Please note that Canadian mobile carriers forbid sending application-to-person (A2P) messaging using long code phone numbers, but US Toll-Free numbers can be used for sending A2P traffic on most Canadian carriers. For a comparison of number types for the US and Canada, see here.
Outside of the United States and Canada, your possible sender types include:
Please note that only US/Canadian Toll-Free numbers can send A2P SMS. When sending messages to non-US countries, carriers treat US Toll-Free numbers just like any other non-local long code phone number.
In some countries, using a local, familiar phone number can improve the read rate of your messages. Using a local number or short code is also required in order to receive incoming replies - see Receiving Two-Way SMS and MMS Messages with Twilio for details. Depending on your use case and the relevant country regulations, you may want to add in-country numbers to your Messaging Service for each country you want to send SMS to.
When selecting senders for your Messaging Service, also consider the flow of content that you'll send to your customers. Message content affects which sender types are available for you to include in your Messaging Service.
There are two main types of messaging to consider:
Common examples of one-way messaging include marketing messages, delivery alerts and other informational messages.
If you plan to send one-way traffic through your application, you will need to choose your sender type based on what is available and permitted by local regulations for your specific use case in the countries you plan to send messages to. For example, France prohibits the use of local long code numbers for anything except for pure person-to-person (P2P) conversation traffic, so most organizations will need to use an Alphanumeric Sender ID or a short code to send messages to France.
Depending on availability and per-country regulations, you may use one or more of the following sender types in your Messaging Service's Sender Pool:
Common examples of two-way messaging are chat bots, virtual assistants, and appointment reminders.
For two-way, back-and-forth messaging, you should include one or more of the following in your Messaging Service's Sender Pool:
Message throughput is measured in Messages Segments per Second, but typically abbreviated as MPS. Your throughput needs affects which types and how many senders you should add to your Messaging Service's Sender Pool.
MPS varies by country and by sender type. For US long codes, the MPS you get depends on the outcome of your A2P 10DLC registration. For US Toll-Free, the default MPS is 3, but this can be increased. Outside of the US, it's typically 10 (ten) messages per second. For details, see Understanding Twilio Rate Limits and Message Queues.
Using multiple long code or Toll-Free numbers to increase your message throughput to the US or Canada is strongly discouraged as it will result in carrier filtering.
For the US, you can get a short code number, which can send messages at 100 MPS or more. Or you can use a single Toll-Free number and talk to Sales about upgrading the number for high-throughput of 25+ MPS.
For Canada, short codes (offering 100+ MPS) and TF are the only permitted ways to send A2P traffic. Using long codes to send A2P messaging traffic will result in increased carrier filtering.
Your options for increasing MPS depend on your traffic type (one-way vs. two-way and A2P vs. P2P, discussed above) and the type of sender(s) you've decided to use.
Alphanumeric Sender ID: by default, Alphanumeric Sender ID offers 10 MPS and its use is country specific. To increase MPS on an Alphanumeric Sender ID, talk to Sales or submit a Support request. Include your expected message volume to the country or countries to which you will send messages.
Long code numbers: by default, long code numbers sending to non-US/Canada countries offer 10 MPS. The MPS on an individual number cannot be increased, but you can add more numbers.
Twilio has built a highly available, distributed queue, so you don't have to worry about these limits. Your application can send Twilio's Programmable Messaging API requests as quickly as you'd like. We'll queue your messages for you and send them out at the appropriate rate for your senders. This keeps your application in compliance, but this can delay the delivery of your messages.
To find out more details, read this article about Twilio Rate Limits and Message Queues.
We caution against adding more long code phone numbers to your Messaging Service's Sender Pool to distribute the load, a practice known as "snowshoeing." Instead, consider upgrading to a sender type with higher throughput, such as a toll-free number or short code, if available in your area.
If you're sending to a country where Twilio offers short code numbers: As of Q4 2022, Twilio offers short code numbers in 14 countries, including the US, Canada, UK, Mexico, and Brazil. Apply for a short code to take advantage of a higher throughput rate, typically starting at 100 messages per second, and robust delivery. Short codes have the advantage of carrier pre-approval; this means that your use case has been reviewed by carriers, greatly reducing filtering risk.
Short codes can only be used to send domestic traffic (e.g., Canadian short codes can only send SMS in Canada.). In addition to using short codes, you should add other numbers or Alpha Sender ID if you plan to send SMS to countries where short codes are not offered, or where a short code does not make sense for your expected message volume.
Please note that in the US and Canada, some smaller mobile carriers may not support short code messages. To achieve the highest levels of deliverability, you should add a few long codes to your messaging service. In the US and Canada, the Short Code Reroute feature will send from a long code phone number when a short code is not supported.
If you're sending to a country where Twilio does not offer short code numbers: Consult the SMS Guidelines for the country in question, and add appropriate numbers to your Messaging Service depending on your use case. For example, for 1-way messaging to many countries in the world, you can add US/Canada numbers to your Messaging Service, or enable Alphanumeric Sender ID.
If you are using an alphanumeric sender ID, it will take precedence over the other phone numbers in your Messaging Service sender pool, even if it has queued messages. Message delivery does not fall back from alphanumeric sender IDs to the long code phone numbers in your sender pool.
If you are planning to use an alphanumeric sender ID in a supported country, make sure that you get the right MPS rate for it. You can request higher throughput on your alphanumeric sender ID through Support.
When you're ready to scale with Twilio Programmable Messaging, we highly recommend moving your application to a Messaging Service, if you have not already done so. That way, you'll have access to all of the built-in features that help you send messages globally and at high-volume, all while managing a single sender pool.
The fastest way to scale your messaging application is to identify your use case and messaging needs from the start. Knowing where you'll be sending messages, what type of content you'll send to customers, and how quickly you need those messages to be sent will point you to the right sender types to include in your Messaging Service.
Also check out: