0

I run a web site on AWS that has a number of web servers (say 4 of them) running behind a load balancer. For this particular web site, I have one license key of New Relic for doing instrumentation. At any one time, I only want one of the 4 web servers to be using the key. If that server goes offline, I want one of the remaining web servers to be able to begin using the license key.

Does anyone know of a service that would let me manage this process? The service would not particularly need to store the key itself but rather just manage the fact that only one web server can lease out the right to use the key at any time. Something where the web servers would have to come back every few minutes and renew their lease, and if they don't it becomes available to someone else.

I just realized I could maybe accomplish a hacked version of this using a file on S3, but that doesn't prevent race conditions / etc and is definitely hackish.

Any thoughts welcome. FWIW, this site is built on Ruby on Rails. Thanks!

JP

1 Answers1

0

It is amazing how answers often pop up after asking a question. I'm pretty sure I can achieve this by just storing the license keys in the database that these web servers already share. The database table would have

  • the license key
  • the ID of the web server that currently has it checked out (this would need to be unique to this particular running instance, eg. its name + PID)
  • the last timestamp at which the check out was renewed

I can make a ruby gem / rails engine that all of the web servers use to interact with this table. When they access the table, they can use locking and transactions to prevent race condition / concurrency issues. If the web server that has the lease on the key goes down, it will not renew its lease. The other servers will periodically check the license and when one of them sees it has not been renewed recently enough, it'll check it out and start using it.