martes, 27 de enero de 2015

Move twilio recordings to azure and save on your twilio monthly bill

Twilio is an amazing cloud communication service which excels in a lot of things, however their recording storage is quite expensive. They charge you by minute stored per month, which means that if you have a recording of 10 mins, you will be charged for those 10 mins each month as long as you keep the recording on twilio's servers. Each account gets 10,000 free minutes per month and after that they charge you $0.0005 per minute per month (details can be seen in https://www.twilio.com/help/faq/voice/how-much-does-it-cost-to-record-a-call). Although this seems pretty low, the minutes start accumulating on your account, because after 3 months, you will be paying, for all the minutes recorded during the first month, plus the ones from the second and the third months too. If you have a high traffic callcenter, you can easily reach millions on minutes in a few months.

I checked multiple recordings, and in average, 1 minute equals 1MB in the recording file. And the minute is their unit, so no matter if your recording is 90 seconds long they charge you 2 minutes for that recording, although they only have to save 1.5MB in their datacenters.

Azure pricing is per GB, and at the time of this writing, its $0.048 per GB using geographically redundancy (6 copies of each file are stored).

Lets compare the costs of storing recordings in twilio versus storing them in azure in a real life scenario which is actually the reason why I did this in the first place. Currently, I'm the lead developer on a call center system that increased the calls that handles 3500 calls per day, with an average duration of 10 mins per call. We noticed that we were paying a lot of money for recording storage and this is the analysis that we did:

Twilio: (3500 [calls per day] * 10 [avg mins per call] * 30 [days in a month] - 10000 [free storage mins]) * $0.0005 [storage cost per min] = $520 per month

Azure: 3500 [calls per day] * 10 [avg mins per call] * 30 [days in a month] / 1024 [MB per GB] * $0.048 [storage cost per GB] = $49 per month

Note: The azure pricing calculation does not include the bandwidth cost of uploading the recordings, but for this same scenario its around $10 extra per month only one time.

So, just by moving the calls to azure we were able to save $471 per each month's recordings storage. And this is accumulable, because if you have been running the call center for 3 months, at the end of the 3rd month, you needed to store the recordings of the first month for the 3 months, plus the recordings of the second month for 2 months, plus the recording of the third month for 1 month. So after 3 months we were able to save $471 * (3 + 2 + 1) = $2826 saved in 3 months
Conclusion, lets the communications provider (twilio) for the communications parts of our solution, and lets use a cloud storage provider for storing the recordings (azure).

I have a github repository with the code needed to move your recordings to azure and start saving on your twilio's monthly bill right away: https://github.com/juanrodriguezcen/twilio-recordings-in-azure

This repository contains 2 projects:

A) MoveRecordingsToAzure: This is a console program that moves recordings from your twilio account to your azure account, including metadata of the recording like the duration and when it was created. This program has a configuration parameter that lets you tell the program to keep the recordings of the last XX days in twilio. If you want to move every recording to azure as soon as its generated, you can set it to 0. In order to move the recordings automatically, you would need to set it up as a windows scheduled task.

B) TwilioRecordings: Is an Asp.net MVC website with just 1 available url (/recordings/{sid}.wav). This url allows you to stream files from twilio and azure transparently. If you have the recording's SID in your db, you can use this url and you dont have to worry if your recording was already moved to azure or if its still in twilio. This website checks if the audio is still in twilio and lets you stream from there (delegating the streaming details to twilio), and if it is not it grabs it from the corresponding azure blob and handles the streaming details by its own (allowing file seeking).

No hay comentarios:

Publicar un comentario