title: Several Multitenant Rails Apps using the same Redis server
body: <p><strong>Scenario:</strong></p>
  
  <p>We have several Multitenant applications that use Sidekiq and Redis.</p>
  
  <p>In each Rails application, we have several accounts. Each account works independently of the other accounts. Each account corresponds to a different client.</p>
  
  <p>For a matter of costs and infrastructure maintenance, we want to use the same Redis server for all the applications. The traffic generated by our Multitentant applications (we have approximately 20 apps, with about 40 accounts) is not excessive for a single Redis server, and therefore our problem is only about configuring that server.</p>
  
  <p><strong>Requirements</strong></p>
  
  <p>We need to uniquely identify each queue of each application/account, so that when Sidekiq acts as a server it processes only its own queues.</p>
  
  <p>The separation / identification could be done at different levels:</p>
  
  <ul>
  <li><p>Separating unequivocally by account</p></li>
  <li><p>Separating unequivocally by machine(application). Each machine(application) has an associated database and within that database account_id are unique. Each Job has an account_id identifier and therefore, knowing which machine (or database) a Job belongs to, we would automatically identify the account.</p></li>
  </ul>
  
  <p><strong>Possible solutions</strong></p>
  
  <p>1- Identify the accounts with a uuid. Each Account would have a uuid field that will be used to name the queues that this account would use in Sidekiq. </p>
  
  <p>Pros: We could easily filter the queues by account, even in monitoring.
  Cons: Many queues would be generated, so if we do not control the polling time to the Redis server we could have performance problems.</p>
  
  <p>2- Use different databases. By Separating databases by machine(application) we would solve the problem of the uniqueness of accounts. The problem is that Redis by default accepts only 16 bbdd and also it numbers them from 0 to 15. So it would be very delicate handling (Manual?) Of these database ids.</p>
  
  <p>3- Use namespaces. Disapproved by Mike Perham <a href="http://mikeperham.com/2015/09/24/storing-data-with-redis/" rel="nofollow noreferrer">http://mikeperham.com/2015/09/24/storing-data-with-redis/</a>
  Namespaces can act as a separator per machine or per queue.</p>
  
  <p>We would really appreciate any help.</p>
  
  <p>Thanks in advance.</p>