Title: Twilio issues with multithreading
Tags: multithreading;architecture;twilio
Question: This is software design question more than a coding one.
I am about to implement a feature where I can verify user's emails and phone numbers using Twilio's sms and voice apis.
My current implementation instantiates a Voice client at start up of the app and then I reuse this client whenever any user decides to verify email or voice.
Question: Is it a good idea to instantiate Twilio client once and then re-use it each time or should I create a new one each time it is needed?
I have browsed the Net for articles but haven't found something conclusive. Hoping to clarify here.


Here is another answer: I'm not familiar with Twilio. But usually, since 3rd party API is out of our control, its stability, performance, etc, are all questions, and potentially, you might want to change to another service provider. So, firstly, try your best to decouple your own logic from 3rd ones. For instance, design an interface for this logic, and one implementation for Twilio.
Secondly, you need to test the Twilio client instance, ensure it could keep working for long time after instantiated, and if your programming language or runtime work in multi-thread way, you need to also test to make sure the instance could work properly when it is shared by multi-threads (if not, the instance is not threadsafe, you might consider using some mutex style locking on it).
Furthermore, if the 3rd party services execution is not stable, or, takes time for execution, etc, and specifically, for your email/sms verification case, it is not necessary to call the services synchronously and wait for responses. You could consider to use a worker queue, putting all tasks to the queue, and create some workers, running in asynchronous threads, to get tasks from queue and execute.
Comment for this answer: thanks teddy, first and third are done. just checking out how to do the second.

Here is another answer: You are looking at whether the twillo client is thread-safe.  A quick google search found this:  Twilio Threaded Messages.  I have not looked at the source myself, but I would consider this a likely answer that yes, it is thread-safe.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:03/01/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<multithreading><architecture><twilio>', 'Title': 'Twilio issues with multithreading', 'ViewCount': 641, 'id': 35721183, 'user_AboutMe': '', 'user_AccountId': 7245599.0, 'user_DisplayName': 'RPV', 'user_Reputation': 407.0, 'user_Views': 57.0, 'user_id': 5527610.0}}