Network Coordinates

    All of this is provided through the use of the Serf library. Serf’s network tomography is based on , with some enhancements based on other research. There are more details about Serf’s network coordinates here.

    Network coordinates manifest in several ways inside Consul:

    • The command can be used to query for the network round trip time between any two nodes.

    • Prepared queries can automatically fail over services to other Consul datacenters based on network round trip times. See the for some examples.

    Consul uses Serf to manage two different gossip pools, one for the LAN with members of a given datacenter, and one for the WAN which is made up of just the Consul servers in all datacenters. It’s important to note that network coordinates are not compatible between these two pools. LAN coordinates only make sense in calculations with other LAN coordinates, and WAN coordinates only make sense with other WAN coordinates.

    Working with Coordinates

    Sample coordinate from Coordinate endpoint

    All values are floating point numbers in units of seconds, except for the error term which isn’t used for distance calculations.

    Here’s a complete example in Go showing how to compute the distance between two coordinates: