Level 2: Twilio Innovator

Lesson: Twilio Messaging in Production

Step 1: Choosing a long or short code

Twilio Messaging in Production

The goal of this lesson is to help you make smart decisions to ensure all your messages are delivered. We will discuss several important details to consider while developing and after launching your messaging application. If you're building or have launched a Twilio messaging application you won't want to miss the information discussed in this lesson.

The first section describes the considerations of choosing a Twilio long code or short code, and how to effectively use them.

Next we review the optimal settings for sending messages globally.

Finally we will discuss the best practices you may take as you launch your alerts and notifications application into production.

Long code or short code

In an earlier lesson , we learned that Twilio enables you send and receive messages using either short codes or long codes.

A long code is a standard 10-digit phone number, and all new Twilio accounts are assigned a long code for use in development. In the US, the wireless industry trade group has designated that long codes are intended for person-to-person communications and are not meant for marketing or high-volume messaging. At high volumes, or when sending marketing messages, you may find that carriers filter your long code messages and they will not be delivered. To help prevent this, Twilio long codes are rate limited and only send messages at a maximum rate of 1 message per second.

Although the carriers don't share their criteria for long code filtering, we have observed behavior that can be flagged includes:

  • Sending many messages that contain similar bodies
  • Sending links in messages
  • Receiving "stop" messages to your number
  • Sending a lot of messages over a short amount of time

For cases such as alerts and notifications, we recommend the use of a Twilio short code. Short codes are a 5 or 6 digit number approved by the carriers for automated or bulk messaging. Short code messages are white listed from carrier filtering, and Twilio will send these messages at a much faster rate of 30 per second (or higher, up to 120). However unlike long codes, which can be instantly provisioned, Twilio short codes are subject to a 3 month carrier approval process and carry a higher cost than long codes.

To summarize the key differences between long codes and short codes:

  • Long codes can send only one message per second per number, and may get filtered or suspended for sending to more than a couple hundred unique contacts per day.
  • Short codes can send 30 messages per second and will not be suspended or filtered, but carry a higher cost and cannot be instantly provisioned.

To learn more about short codes vs. long codes, check out the Short Codes, Big Lessons blog post, or Short code FAQs for answers to common questions.

Knowing when you need a short code

One of the trickiest things about short codes is recognizing when you need one. While many applications launch in production with a long code, to accommodate high volume messaging and to avoid message filtering many will need to transition to a short code. If you use a long code to send more than a few hundred messages in a day, your messages will be in danger of being filtered – or, worse, your long code could be fully suspended. That means zero messages will get through to your end users, which is not a good spot to be in. As short codes carry a greater cost, you may find yourself weighing the added benefits of carrier whitelisting and high volume send against the additional expense.

Although there are no hard rules, as a quick rule of thumb, consider the following:

  • If you're sending 6 or fewer messages per minute, a single long code may be sufficient.
  • If you're sending messages to fewer than 200 unique users in a day, a single long code may be sufficient.
  • If you're sending messages to fewer than 1,00 unique users in a day, rotating your message sending over multiple long codes (as described below) can help
  • If you're sending to more than 1,000 unique users in a day, you are a good candidate for a short code.
  • If you need to send messages at rate greater than 1 per second, you are a good candidate for a short code.

Please remember that provisioning a short code is an approximately three month process, where your application is reviewed by all the major carriers. Please keep this in mind when planning, as you may want to provision a short code before launching in production.

Pooling multiple long codes

We've discussed that Twilio long codes are limited to sending 1 message per second, and risk message filtering by carriers when used to send to more than approximately 200 unique recipients per day, or more than 6 messages per minute. However, these limitations are applied on a per number basis. By making use of multiple long codes, you can send at a greater throughput, and reduce the unique contacts each number sends messages to, reducing the risk of filtering or suspension.

Here's how you can use a round robin approach to balance sending your messages over a series of long codes.

  1. Provision a series of long codes into your Twilio account, using the account portal or REST API .
  2. In your application, define a list or array to track the long codes you'll use as From numbers when sending SMS, and an cyclic iterator or pointer to the current member of the list. Tracking these variables at the class or application scope may help, to create a central place to store round robin data in your application.
  3. Create application code which wraps sending of SMS. For example, create a class containing a function which calls the Twilio SMS API, each time using the next member of your number list as the From parameter. A static function may be helpful to keep the current round robin position in memory.
  4. Optional - If your focus is to limit unique recipients messaged per long code, use an array of To numbers, and round robin which From number is used to send to each recipient. This will create a 'sticky' From number for each recipient, rather than simply distributing messages evenly over all long codes.

Here is example code for the pooling of long codes:


Please select an available language.

Please Note - The mobile carriers each have their own message filtering criteria. While using a pool of long codes may provide some extra legroom for certain use cases, it does not guarantee that carriers will not filter messages. This approach won't scale well past 10 or so long codes. If you are exceeding 1,000 messages per day we strongly recommend you look into a Twilio short code.

Test Your Knowledge

Question 1 of 3

Which type of phone number can send SMS messages at 30 per second and is white listed by carriers from message filtering?



Correct. 

Short codes are a 5 or 6 digit number approved by the carriers for automated or bulk messaging. Short code messages are white listed from carrier filtering, and Twilio will send these messages at a much faster rate of 30 per second (or higher, up to 120).

Incorrect. 

Long codes can send only one message per second per number, and may get filtered or suspended for sending to more than a couple hundred unique contacts per day.

Question 2 of 3

When messaging from a long code, which of these can potentially cause a message to be filtered by carriers?





Correct. 

Although the carriers don't share their criteria for long code filtering, we have observed these behaviors can be flagged for filtering. Using a short code to send messages removes the risk of message filtering.

Incorrect. 

There is a more complete answer, try again.

Question 3 of 3

How long does it take to provision a short code for your Twilio application?





Correct. 

Please remember that provisioning a short code is an approximately three month process, where your application is reviewed by all the major carriers. Please keep this in mind when planning, as you may want to provision a short code before launching in production.

Incorrect. 

It takes a bit more time than this, try again.

Next Question 

 Previous Question

Congratulations, you have completed the quiz.

Congratulations, you have completed the quiz.

You scored {{pageC.completed.contentStatus['long-short-code-quiz'].score}} of {{pageC.completed.contentStatus['long-short-code-quiz'].possible}} possible points.


Next Step: Messaging Best Practices



 


Powered by