Implementation Notes

Using Redis to Share Real Time Data among Servers

vteam #678 has been working on a telephony web application. To increase the capacity (concurrent users) and reliability of the application, the client required load balancing so that the agents (users) can login from any of the three servers. Additionally, the application’s admin panel was required to display and control the status of all the active agents on any of the three servers.

As the status of agents was changing continuously, some real time features were required. In addition to it, the real time data (like 100 changes per second) must be stored somewhere so that it could be accessed and manipulated later quickly. The following could be the possible solutions to store real time data but it is recommended not to:

  • Make dozens of database queries per second
  • Share the sessions of the three servers
  • Share the files of the three servers
    .

Solution

After doing some R&D, it was proposed and later decided to use Redis because it supports many data structures including:

  • Strings
  • Sets
  • Lists
  • Hashes, etc.
    .

vteams engineer stored the real time data of the client’s application in Redis Hashes. To hold the database, the application already had a dedicated server. The same server was used for Redis. It was then configured to accept external connections.

To implement the above mentioned solution, setup redis as per the instructions given in the laravel docs. This setup included the “predis/predispackage for Laravel. Since the application had two user guards i.e. “user” and “admin”, it was decided to define a trait which would be responsible for all the communication with Redis.

Conclusion

As a result, the three servers were then able to share their data in an extremely fast data store.