News for hackers. Stuff that matters.
Re:What happens when you update your DNS by jrockway on Monday June 22, 2020 @05:36PM (#23607044)
This reminds me that I wish DNS had some way to define a load balancing algorithm for clients to use, so browsers could make load balancing decisions. This would eliminate the need for virtual IP addresses, having to pass originating subnet information up recursive queries, having to remove faulty VIPs (or hosts) from DNS, etc.

It is baffling to me that inside the datacenter, I can control the balancing strategy for every service-to-service transaction, but for the end user's browser, all I can do is some L3 hacks to make two routers appear as one (for failover purposes). L3 balancing would be completely unnecessary if I could just program the user agent to go to the right host, after all. The end result is unnecessary cost and complexity multiplied over a billion websites.

Re:What happens when you update your DNS by LinuxBender on Monday June 22, 2020 @05:50PM (#23607237)
That is a use of SRV records [1], however it was not accepted into the HTTP protocol specification. I bring it up every time there is a new protocol version but I am too lazy to write an RFC addendum for it and hope that someone else will. Existing protocols may not be modified in this manor once ratified. Maybe HTTP/4.0? /s

Some applications use SRV records for load balancing. Many VoIP and video conferencing apps do this. There is a better list on Wikipedia.

    _service._proto.name. TTL class SRV priority weight port target.
[1] - https://en.wikipedia.org/wiki/SRV_record
Re:What happens when you update your DNS by jrockway on Monday June 22, 2020 @06:13PM (#23607493)
Yeah, I always liked SRV records. It seems that they proved inadequate for gRPC balancing, so there are new experiments in progress (mostly xDS).
Re:What happens when you update your DNS by aeden on Monday June 22, 2020 @06:14PM (#23607507)
FWIW, there is an IETF draft that may be suitable for addressing this: https://datatracker.ietf.org/doc/draft-ietf-dnsop-svcb-https...
Re:What happens when you update your DNS by jrockway on Monday June 22, 2020 @06:29PM (#23607665)
Aha, this sounds like exactly what I was looking for!
Re:What happens when you update your DNS by m3047 on Monday June 22, 2020 @06:30PM (#23607675)
> [...] I wish DNS had some way to define a load balancing algorithm for clients to use, so browsers could make load balancing decisions.

There's actually the germ of an interesting idea in that statement. If I'm going to go to the trouble, let's say, of running a local TCP forwarder (good for the whole device), can I run a packet sniffer at the same time and watch netflows and edit the responses I return to the device based on what I see performance-wise concerning those flows?

Expert me says that web sites are loaded with too much cruft and since the far end terminations are spread far and wide, there's not enough opportunity to apply that learning in any practical sense. But I could be wrong. (https://github.com/m3047/shodohflo)

Re:What happens when you update your DNS by m3047 on Monday June 22, 2020 @08:15PM (#23608520)
Why doesn't a stub resolver do this, and try (plain) TCP and DoT (port 852) opportunistically while it's at it: you know, good for the whole device?
Re:What happens when you update your DNS by m3047 on Monday June 22, 2020 @08:38PM (#23608731)
> port 852

Typo, meant 853.

Re:What happens when you update your DNS by jlgaddis on Tuesday June 23, 2020 @10:15AM (#23614161)
FWIW, you can edit your own comments for up to two hours.
Re:What happens when you update your DNS by jeffbee on Monday June 22, 2020 @08:12PM (#23608498)
As DNS-over-HTTPS spreads I expect to see a lot of innovation in DNS including stapling load-distribution directions along with the RRs.
Re:What happens when you update your DNS by 1996 on Monday June 22, 2020 @05:51PM (#23607250)
How would it be better than round robin DNS with low TTL?
Re:What happens when you update your DNS by jrockway on Monday June 22, 2020 @06:17PM (#23607543)
Basically, it affords you the ability to cache for longer and still end up with users able to go to your website.

Right now, you can try resolving common hosts, and you will see that they often provide several hosts in response to a lookup. What the browser does with those IPs is up to the browser, the standard does not define what to do. What the administrator that sets up that record wants is "send to whichever one of these seems healthy", and some browsers do do that. Other browsers just pick one at random and report failure, so your redundancy makes the system more likely to break.

What I want is a way to define what to do in this case. Maybe you want to try them all in parallel and pick the first to respond (at the TCP connection level). Maybe you want to try them sequentially. Maybe you want to open a connection to all of them and send 1/n requests to each. Right now, there is no way to know what the service intends, so the browser has to guess. And each one guesses differently.

(You will notice that people like Google and Cloudflare skillfully respond with only one record with a 5 minute TTL. That is so the behavior of the browser is well defined, but it also eats their entire year of 99.999% uptime with one bad reply. Your systems had better be very reliable if DNS issues can eat a year's worth of error budget.)

Re:What happens when you update your DNS by achiang on Monday June 22, 2020 @08:37PM (#23608721)
> (You will notice that people like Google and Cloudflare skillfully respond with only one record with a 5 minute TTL. That is so the behavior of the browser is well defined, but it also eats their entire year of 99.999% uptime with one bad reply. Your systems had better be very reliable if DNS issues can eat a year's worth of error budget.)

This chapter in the Google SRE book explains how our load balancing DNS works:

https://landing.google.com/sre/sre-book/chapters/load-balanc...

Source: my team runs this service

Re:What happens when you update your DNS by 1996 on Monday June 22, 2020 @10:54PM (#23609482)
I skimmed though, not a bad idea- instead of using a reverse proxy, you are basically doing a poor man multicast, by letting many servers answer a request. And instead of rewriting the packets, you encapsulate, which should be lighter and faster.

It might be a little more resilient than even a very minimal nginx, but more than that, I think it must give you more control about what happens when a packet is not "answered" after some set amount of time - you write off who should have been the answerer, then resend that same packet to another server. Keep a buffer of packet, scrape them from the buffer when ACK'ed by the answerer, resend them to another answerer if not ACK'ed after some set amount of time.

Am I guessing correctly?

It seems a bit overcomplicated for normal usecases, but adequate for a large scale like google.

Re:What happens when you update your DNS by achiang on Tuesday June 23, 2020 @01:41AM (#23610280)
The design you propose is stateful, and if you read the chapter closely, you can see we spend a lot of effort to make things stateless.

The main thing I wanted to respond to in this thread about a single bad server destroying your yearly SLO is described in the first paragraph in the section on load balancing at the virtual IP address.

Re:What happens when you update your DNS by blueblisters on Tuesday June 23, 2020 @05:01AM (#23611480)
Sorry I couldn't find a clear rationale in the link. Why does Google prefer a stateless load balancer? Is it infeasible to maintain state at that scale?
Re:What happens when you update your DNS by 1996 on Tuesday June 23, 2020 @02:00AM (#23610375)
Sorry, I didn't read the document that closely. It was a bit too long.

Overall, virtual IPs are still an interesting solution.

Re:What happens when you update your DNS by jrockway on Tuesday June 23, 2020 @04:10AM (#23611148)
Re:What happens when you update your DNS by 1996 on Monday June 22, 2020 @07:27PM (#23608172)
> What the administrator that sets up that record wants is "send to whichever one of these seems healthy

In the rrDNS, remove the A record of the hosts that fails tests, or that has a load that's too high

> Maybe you want to try them all in parallel and pick the first to respond (at the TCP connection level).

Something a geoIP at your DNS can do, certainly not as good as doing that in the client, but it should be decent enough.

> Your systems had better be very reliable if DNS issues can eat a year's worth of error budget

Or, if you aren't google or cloudflare, use a 30 to 60s TTL in rrDNS, with health checks to selectively remove IP that fail, on pools splitting your servers by region with geoIP - this way, if 1/10 of your east coast servers fail, nobody from APAC will be impacted, and only 1/10th of your US east users, and only for the TTL (I'm abstracting ISP that cache for too long, but you already mitigate a lot of the problem there)

I can see how it would be easier to handle that in the browser, but you may already be able to do that with some JS to estimate the latency, then store the result in a cookie that causes a reload to www.eastcoast.yoursite.com if the user sticks to www.yoursite.com or after returning home goes to www.apac.yoursite.com while new measurement say "not optimal" and update the cookie

Re:What happens when you update your DNS by jrockway on Monday June 22, 2020 @11:00PM (#23609503)
I am kind of OK with this solution, and is in fact my plan to roll out HTTP/3 for my personal sites. I wrote https://github.com/jrockway/nodedns to update a DNS record to contain the IP addresses of all schedulable nodes in my cluster. I can then serve HTTP/3 on a well-known port and it is probable that many requests will reach me successfully. (I had to do this because my cloud provider's load balancer doesn't support UDP, and I don't have access to "floating IPs"; basically my node IPs change whenever the cluster topology needs to change.)

I don't really like it because it still means a minute of downtime when the topology does change. I would prefer telling the browser what strategy to use to try a new node, rather than relying on heuristics and defaults.

Re:What happens when you update your DNS by m3047 on Monday June 22, 2020 @08:21PM (#23608570)
Unless you're using DoH, in most cases the browser is using the device's stub resolver just like all other apps on the device.
Re:What happens when you update your DNS by m3047 on Monday June 22, 2020 @06:17PM (#23607539)
DNS has its own load balancing at several levels (and several different kinds):

Nameserver records (NS records) used to locate a resource are served by other nameservers. NS records are chosen from among those offered in response to a query (RRs), and should all be tried if necessary to elicit a response. The algorithm isn't strictly specified and some nameservers will shuffle the order in which they return RRs in their answers, some won't assuming the stub resolver or app will do it. The foregoing also applies to A and AAAA records (returning IP addresses for names), and this has long been used as a quick and easy form of load balancing/failover, except that it doesn't really failover very well unless your app is coded to try all of the different answers (and the stub resolver returns them to your app).

Nameservers querying other nameservers (caching/recursive resolvers) are supposed to compile metrics on response times when they make upstream requests and pick the fastest upstreams once they learn them.

Stub resolvers (running on your device) typically query nameservers in the order you specified them in your network config, but not always.

From the foregoing, you can probably see that running a caching/recursive resolver close to your devices is supposed to be desirable, by design.

So far, so far. ;-)

As specified, and it's never been changed, DNS tries UDP first. "Ok", you think "that must mean it will try TCP" but that's not actually true: it only tries TCP if it receives a UDP response with TC=1 (flagged as truncated). But if there's a UDP frag and it doesn't get all the frags or never gets a UDP response at all it /never/ tries TCP.

You're mixing two very different environments above: 1) a datacenter with (let's just assume) VPCs and 2) a web browser.

In case #2 I'll match your ante and raise you an overloaded segment which is dropping UDP packets, in which case stuff may fail to resolve at all. Oh look, I drew a wildcard: traditionally browsers have utilized the devices stub resolver, but since they've pushed ahead with DoH they've had to implement their own. People think I'm a DNS expert (what do they know?) and I guess conventional wisdom amongst myself and my peers is that UDP should perform better than TCP but anecdotally people are claiming that DoH and DoT perform better for them than their stub resolver. "Must be your ISP messing with you" says someone, "yeah right, that's gotta be it". Me: "did you try running your own local resolver?" them: "wuut?"

So here's where I confess that the experts aren't always right, because I run my own local resolver and I have the same problem: when the streaming media devices are running DNS resolution on the wifi-connected laptop sucks and if I run a TCP forwarder it starts working! (https://github.com/m3047/tcp_only_forwarder).

Now to case #1, the datacenter. I hope you're running your own authoritative and caching server, and you should read about views in your server config guide; using EDNS to pass subnet info is a kludge. If you're writing datacenter apps, you should consider doing your own resolution and using TCP (try the forwarder, I dare you), and provisioning accordingly (because DNS servers assume most requests will come in via UDP).

If you want load balancing "you know, like nginx" I've got news for you: BIND comes with instructions for configuring nginx as a reverse TCP proxy. Oh! Looks like I've got a straight in a single suit: nginx provides SSL termination so I've got DoT for free!

Re:What happens when you update your DNS by jrockway on Monday June 22, 2020 @06:25PM (#23607624)
I am not really talking about load balancing the DNS traffic, I'm talking about interpreting the response of the DNS query. (The reliability at the network level seems to be handled by moving everything to DNS-over-HTTPS or something, and is a debate for another day.)

For example, consider the case where you resolve ycombinator.com. You get:

    ycombinator.com.        59      IN      A       13.225.214.21
    ycombinator.com.        59      IN      A       13.225.214.51
    ycombinator.com.        59      IN      A       13.225.214.81
    ycombinator.com.        59      IN      A       13.225.214.73
Which of those hosts should I open a TCP connection to to begin speaking TLS/ALPN/HTTP2? The standard doesn't say. I would like a standard that says what to do. (The more interesting case is, say I pick 13.225.214.21 at random. It doesn't respond. What do I do now? Tell the user ycombinator.com is down? Try another one? All of this could be defined by a standard ;)
Re:What happens when you update your DNS by m3047 on Monday June 22, 2020 @08:07PM (#23608465)
Perfect example. :-) There's not enough information to make a considered response, unless you've got a history of opening TCP connections to them to base a decision on.

Don't get me wrong, I think stub resolver logic is stuck in the 1980s!

If your app or device doesn't have such a history, and no way to obtain it, then maybe the server can do it based on what it knows about its history with IP addresses "close" to yours (the EDNS kludge).

> It doesn't respond. What do I do now? Tell the user ycombinator.com is down? Try another one? All of this could be defined by a standard

I would argue the DNS is clear about this from its own behavior: it tries another one.

Although it's not clear from `pydoc3 socket.create_connection`, it's pretty clear from https://docs.python.org/3/library/socket.html#creating-socke... that socket.create_connection() that it will "...try to connect to all possible addresses in turn until a connection succeeds."

So I would say that the correct action would be to try all possible addresses until one succeeds.

Re:What happens when you update your DNS by toast0 on Monday June 22, 2020 @10:49PM (#23609460)
> Which of those hosts should I open a TCP connection to to begin speaking TLS/ALPN/HTTP2? The standard doesn't say. I would like a standard that says what to do.

Well, there was an RFC (found it, RFC 3484) that told you to pick the one closest to your network (which wouldn't make a difference in this case, unless you were in say 13.225.214.0/27 or so). But that's not actually helpful, because given two destination IPs, one in the same /8 as me, and one not, I don't have any information that would help me determine which is a better choice.

From experience, most browsers will try a couple IPs before showing an error message, but that's not standard. If you have a fancy authoritative server, a lot of traffic, and a bunch of server IPs, you can get OK balancing by telling some clients some IPs and some clients other IPs; but it depends on having enough diversity in recursive servers; if all of your users are coming from one mobile ISP, chances are you won't get a lot of balancing.

(And I'm sure you already know all this :)

Better to have clients with a bit of intelligence. :)

Re:What happens when you update your DNS by kokey on Tuesday June 23, 2020 @06:39AM (#23612139)
I think the main problem with great ideas like this is that some clients will do a really bad job at implementing the spec correctly and one of those clients will be the default browser on a very popular OS or device.
Re:What happens when you update your DNS by rswail on Tuesday June 23, 2020 @09:32AM (#23613658)
Isn't that what SRV records are for? If there's one for _http specifying ycombinator.com as the name, then any of those IP addresses should accept a connection on port 80 speaking HTTP. Without independent names, they should all be treated equally and your app (like a browser) gets to try just one or all of them.

If you're talking about subprotocols/versions of HTTP like HTTP2 then you can define subservices, so you could have _http2._http. But no one has proposed that yet :)

Of course with anycast, multiple A records can be redundant :)