Take the 2-minute tour ×

I have a number of services running on various machines which need to communicate over arbitrary ports. Right now port discovery happens by pushing a config file to each machine which contains mappings of a service-name to a hostname/port combo.

For all the same reasons that DNS works better than manually maintaining an /etc/hosts on each machine, I'd like to have a centralized system to register and lookup these hostname/port combos.

Yes, building a simple version of this system wouldn't take long at all (it's just a key-value store), but ideally the service would be fast, redundant, auto-updating and have fail-over, which would obviously take a bit more time to build from scratch.

I can't imagine I'm the first to need such a tool, but so far my Google-fu has failed me. Is there something out there built for this purpose? Or should I just set up Kyoto Tycoon or ZooKeeper and write a bit of caching/lookup/failover logic myself?

share|improve this question
DNS is a public system, port numbers were never meant to be public. Could you instead use one default port to "agree on a port number" over? –  Jasper Feb 5 '12 at 1:38

3 Answers 3

DNS supports SRV records that are designed just for this (service location.)

SRV records are of the following form (courtesy Wikipedia):

_service._proto.name TTL class SRV priority weight port target
  • service: the symbolic name of the desired service.
  • proto: the transport protocol of the desired service; this is usually either TCP or UDP.
  • name: the domain name for which this record is valid.
  • TTL: standard DNS time to live field.
  • class: standard DNS class field (this is always IN).
  • priority: the priority of the target host, lower value means more preferred.
  • weight: A relative weight for records with the same priority.
  • port: the TCP or UDP port on which the service is to be found.
  • target: the canonical hostname of the machine providing the service.

Most modern DNS servers support SRV records.

share|improve this answer

Avahi advertises services (by port) that each machine offers. (aka Apple's Bonjour)

Not sure if it's exactly what you're looking for, but definately in this vein. The concept is that each machine would announce what services it is running on each port.

But this is limited to a LAN implementation, which I'm not sure fits your requirements.

To add a little more meat to this answer, here is an example service file for Avahi advertising a webpage:

  <name replace-wildcards="yes">%h Web Server</name>
share|improve this answer

I personally think zookeeper is a great fit for this use case. Ephemeral nodes mean that registration cleanup is not a problem, freeing you to use dynamic port allocation on the server side and watches will help with rebalancing client->server mappings. That said, using zookeeper for server side registration and using DNS SRV records for client side lookup(using a zookeeper to dns bridge) would work well for most use cases.

share|improve this answer

Your Answer


