NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache (blog.cloudflare.com)
lpapez 7 hours ago [-]
This is the right way to deliver software.

Produce working product first, validate the idea, stabilize the business, start generating profit, and then you can start optimizing your costs.

In fact optimization is by far the easiest part of the process because there are many system programming experts on this HN thread who consider these optimizations to be trivial.

brainless 10 minutes ago [-]
I do not think Cloudflare was a less-than-peers optimized product when they launched. This is one of their blog posts which describes taking one aspect even further.

I think Cloudflare became big only because they were so much more optimized than others that they offered some services for free that others were not offering. If internet costs are high, you only burn (VC) cash and then you exit.

sandeepkd 2 hours ago [-]
Its a yes if you do not know the domain space, query patterns well enough and also if the cost of optimization or time for optimization may have detrimental impact to business. In this case it most likely means that the crowd in the room did not anticipate much on this in early phases and no one in the room pointed these things out. The irony is that these performance and disk numbers are heavily discussed as a part of system design interviews.

> In fact optimization is by far the easiest part of the process because there are many system programming experts on this HN thread who consider these optimizations to be trivia

This is a misconception when you including roll out as a part of the change too, changing data once its running in production is hard, changing the data structure is even harder and when you talk about making changes in cache which is at the hot path its probably the hardest. Looking at the graph at the end it looks like it took them 4+ months to roll out the changes after optimization.

vanviegen 7 hours ago [-]
Or optimize a bit earlier and prevent having to scale out to a bazillion systems.
bcrosby95 7 hours ago [-]
The way I usually prevent having to scale out to a bazillion systems is never getting more than 10 users.
bigbuppo 3 hours ago [-]
And that's why I charge $10,000,000/user/mo.
steve_adams_86 6 hours ago [-]
I wonder why Cloudflare didn’t think of this
kevin_thibedeau 6 hours ago [-]
This is Broadcom's business model
gerdesj 4 hours ago [-]
Quite. I was a VMware fanboi (25+ years, man and boy)

I still look after a few VMware estates and a lot of Proxmox ones (that used to run VMware).

Hilariously, VMware is described as "enterprise class", which I can only conclude means MVP and a bit wanky.

Today I repaired a Proxmox HA + Ceph node using boring old normal Linux skills and as it turns out I have 30 years of those. Part way through a remote v8 to 9 upgrade I think I lost comms due to using OpenvSwitch for networking and despite using tmux for the upgrade session. Anyway, the Proxmox ISO was useless for rescue but the classic systemrescuecd worked nicely and I could run dpkg in a chroot.

VMware "used" Linux and never really gave back. I don't miss fixing vCentres and all the other nonsense that "Enterprise" wankery has foisted on me over the years.

taneq 4 hours ago [-]
When I was first getting into software dev, I thought 'enterprise' meant 'industrial grade', 'powerful', 'high-performing'.

Then I actually met some enterprise software, and realised that it means 'expensive', 'bespoke', 'one-off', and usually 'janky'.

phoghed 4 hours ago [-]
Enterprise means it has SSO and a support contract
jacquesm 56 minutes ago [-]
It means you are paying for a support contract. Whether you actually have one time will tell.
esseph 2 hours ago [-]
Lol, so true
Nursie 10 minutes ago [-]
To me it always meant needlessly complex and overspecced for what's needed. I think probably due to Java's enterprise years.

Why solve the problem directly when you can abstract everything away into FactoryFactoryImplementationInterfaceFactorys, and have something that is both a memory-hog and completely unassailable to any normal programmer seeking to understand it or make changes?

bigbuppo 3 hours ago [-]
Enterprise quality software is a just a DOS application, probably written for dBase III, that has been rolled forward to the present day.
bch 7 hours ago [-]
The Art of Production
forgot-my-pw 5 hours ago [-]
The art of premature optimizations
froh 7 hours ago [-]
pro move. made my evening.
scottlamb 2 hours ago [-]
You're never going to get promoted with that attitude!

I'm joking...but not entirely. It sounds impressive on a promo packet when you say you've saved 100 TB of RAM / $$$ through whatever technique. But it sounds a lot less impressive when you say if this system grows to this size in x years, I will have saved 100 TB, especially when no one yet knows how large the system will really be in that time or what the cost of RAM will be. I dunno, maybe if you say that x years ago, I made a decision that now is saving us 100 TB, that's kinda impressive, but you're also getting credit for it x years after you did the work. It also doesn't have the implication that it must be inherently complex/hard because some other smart person chose the other way. And there is a bias to care more about recent accomplishments. So I don't really think it'd be valued the same at all.

Also, in general big tech (at least Google) prefers growing the userbase over improving efficiency. Periodically efficiency is rewarded, e.g. when RAM cost suddenly balloons or some big must-have feature has suddenly used up capacity planned for something else. You get rewarded for doing efficiency work on demand, not eagerly.

I once got a $100 peer bonus for finding 100,000 cores that were essentially stranded by an accounting error in another team's migration script.

Dylan16807 54 minutes ago [-]
It was already reasonably lean. If they had 10 bazillion systems, they now need somewhere between 6 and 8 bazillion systems.
7 hours ago [-]
dakolli 1 hours ago [-]
You can build foundations that aren't extermely optimal but have future optimisations in mind.
nine_k 4 hours ago [-]
This assumes that you have plenty of cash to burn in the process, which is approximately correct for VC-backed ventures, and for offshoots of large corporations that play a lomg game.
aeonfox 3 hours ago [-]
> start generating profit, and then you can start optimizing your costs

Good thing they jumped on that as soon as they were profitable instead of burning cash. Oh wait...

I think a distinction to draw here is that Cloudflare had relatively large capital raises and were almost immediately profitable¹. They had the luxury of throwing away money. Judicious optimisation makes sense for scrappy start-ups, especially when trivial optimisations like these could easily be farmed off to an agent.

¹ https://timeline.www.cloudflare.com/

casey2 7 hours ago [-]
This reasoning assumes you have access to infinite runway. You don't.
lpapez 6 hours ago [-]
Exactly, and you need to start turning a profit before the end of that runway. Even if that means running code that is suboptimal.
ramon156 6 hours ago [-]
i suppose you could say the same about buying a house. just make that initial 300.000 and from there on out its easy. everything looks better on paper
topato 3 hours ago [-]
My house is a ~700 sqft. condominium, gov. subsidized for lower income individuals, and even my mortgage is more than 300k… maybe I’m just basing my info off of coastal city prices, but is it possible to buy a reasonably nice home located in a reasonably nice amerikkkan city… for $300k in 2026?
esseph 2 hours ago [-]
That would buy you thousands of square feet and often several acres within 20 minute drive to a lot of US city downtown areas.
AlotOfReading 26 seconds ago [-]
Can you ground the discussion by mentioning what you think these cities are? Taking Columbus, OH as the most average of American cities and a 20m isochrone map from city center, there are currently 0 parcels for sale with 3+ ("several") acres. There are a couple within 30m drive, one of which even has a possibly habitable structure. The rest are bare agricultural land you'd need additional investment to actually live on.
8n4vidtmkvmk 2 hours ago [-]
Not from what I've seen. The desirable neighborhoods are 500-600k. Suburbs outside major city
catlifeonmars 1 hours ago [-]
Desirable neighborhoods are by definition expensive. The trick is to find a neighborhood you like where your home can just be a home and not a top-heavy investment.

Acknowledging this isn’t always easy or possible, but just pointing out that this is a self reinforcing problem.

esseph 1 hours ago [-]
You didn't read what I said.

I mentioned acres of land. You normally don't have multiple acres of land in the suburbs.

rcxdude 5 hours ago [-]
This reasoning is largely centered around the runway being finite. You obviously can't have costs so high you are making a huge loss, but also there's little value in improving margins past profitability until you actually have a stable segment of the market.
inopinatus 6 hours ago [-]
we are all perfectly smooth, round, and filled with an incompressible liquid
5 hours ago [-]
rexpop 6 hours ago [-]
Every startup is one bet in a Martingale strategy played by the class of people who remain solvent when you bust.
robocat 5 hours ago [-]
The median return for a startup is $0. Take care when trying to extrapolate cause and effect.
tonymet 4 hours ago [-]
Only if you have loads of capital
MuffinFlavored 4 hours ago [-]
> Produce working product first, validate the idea, stabilize the business, start generating profit,

not everybody is so lucky to be able to go in that order? The first part requires upfront capital/investment?

phoghed 4 hours ago [-]
So obviously you start at optimization
sieabahlpark 5 hours ago [-]
[dead]
irdc 10 hours ago [-]
This is why system programming still matters.

Looks like they're missing the obvious optimisation of putting the record data right after the CacheEntry members instead of allocating memory separately though. But that might just be me as a C-programmer talking and not be all that easy in Rust.

mkeeter 9 hours ago [-]
For the curious, this is technically possible in Rust using a dynamically sized type [1], but in practice is difficult and doesn't really play nice with the rest of the language. The nomicon entry concludes with "Yes, custom DSTs are a largely half-baked feature for now." [2]

[1] https://doc.rust-lang.org/reference/dynamically-sized-types....

[2] https://doc.rust-lang.org/nomicon/exotic-sizes.html

cakoose 7 hours ago [-]
> putting the record data right after the CacheEntry members

I assumed they couldn't do that because they're using it with some kind of generic HashMap<K, V>. In that situation, can "V" be dynamically sized?

A dynamically sized "V" would mean you can't have an array of them, which might preclude some hash map implementations.

esterna 7 hours ago [-]
> All type parameters have an implicit bound of Sized. The special syntax ?Sized can be used to remove this bound if it’s not appropriate.

, which HashMap does not do, i.e. the keys and values have to have a statically known size.

7 hours ago [-]
f311a 7 hours ago [-]
Unfortunately, Rust is not a good choice for this kind of tricks. This is where Zig shines. In Rust, you can’t even use proper arenas, which can help a ton with allocations.

Cloudflare started to pick Zig recently, for projects, that have memory constraints.

afdbcreid 6 hours ago [-]
> In Rust, you can’t even use proper arenas

You definitely can and this is done a lot. What you might mean is that you can't use standard library's collections with them (this is getting stabilized soon!) and have to use third-party, but that is a different thing than "can't use arenas".

> Rust is not a good choice for this kind of tricks.

Rust can do those tricks, but it's true that it is hard than in C or Zig. That said there are often crates to help.

f311a 1 hours ago [-]
Stabilized soon, really? They did not stabilize it after 10 years and were thinking about different approach. I thought it’s dead.
chlorion 3 hours ago [-]
I'd like to know why I can't use arenas in rust? Especially considering that I have used them before in rust.
f311a 1 hours ago [-]
You can’t allocate collections without nightly or without reimplementing them in the library. Every implementation uses it’s own set of trade offs to provide safety in unsafe implementation.
1 hours ago [-]
sdcfgy 9 hours ago [-]
System programming always matters. Things are cheap until they aren't one day.
tehlike 8 hours ago [-]
things are cheap until you reach a scale.
9dev 5 hours ago [-]
Things are cheap until they are someone else’s problem, I say!
7 hours ago [-]
listeria 8 hours ago [-]
Depends on how the CacheEntry is stored, it's probably stored in a slice of &[CacheEntry] which precludes storing the record data alongside it as the size of each entry must be fixed.
irdc 7 hours ago [-]
This is where hand-rolled intrusive data structures, as are traditional in C, really shine.
jiggawatts 5 hours ago [-]
I wish more programming languages implemented record types as seen in databases, where dynamically sized fields are packed into a contiguous area of memory.

The CloudFlare manually implemented a clumsy version of this.

Wouldn’t it be nice for the compiler to manage this for you in the same way that your database engine does when it saves a “row”?

anitil 2 hours ago [-]
> dynamically sized fields are packed into a contiguous area of memory

Are you able to explain this? Do you mean an N sized array where each entry is either a value or a pointer to a value where the 'pointed-to' values are after the end of the array?

I'm trying to underatnd how you'd do this without having to parse M-1 elements to get the Mth entry if you did a [{size0, value0}, ....., {sizeN, valueN}] arrangement

toast0 41 minutes ago [-]
I think they mean the cache entry is a collection of dynamically sized fields. It would be nicer to store that as a single contiguous allocation, rather than a bunch of pointers to individually allocated dynamically sized items. At least in this case, it might.

In a row oriented database, you get a contiguous spot for the whole row even when there are multiple variable width fields.

cobalt 9 hours ago [-]
less ergonomic, but still totally doable
strenholme 9 hours ago [-]
With my own MaraDNS, I aggressively optimized the memory usage of blacklist entries by having a single really big malloc() to allocate the memory for the entries, then traversing that memory block for potentially blacklisted entries.

When I was using one malloc() per entry, a large blacklist took up 237 megabytes of memory. The same blacklist, once optimized to be loaded with a single malloc() call, only took up 9.5 megabytes of memory.

https://samboy.github.io/blog/entries/MaraDNS.html#BlogEntry...

badatnames 4 hours ago [-]
Why do I always find interesting new Twitter accounts just as the person is leaving :)
vinkelhake 9 hours ago [-]
These seem like some fairly standard approaches for reducing memory usage. I can't help to think that the approach of joining several distinct list into a single one in some way undercuts Rust's safety guarantees.

If you previous had three distinct Vec objects, then Rust would guarantee that you can't index out of bounds. If you now put all those objects into a single Vec and rely on offsets, then you now open the door to indexing out of range of these sub-slices without any panics.

It's a minor point, and it doesn't really invalidate the optimization, but I'm surprised the article didn't mention it.

ratorx 8 hours ago [-]
I think it’s more of a time vs code tradeoff, if done properly.

For example in the Vec case, you could theoretically build an alternative which encodes the “three sections” property internally, and ensures correctness at construction time for the pointers. Not as completely safe as a Vec, but you can still get similar benefits for the “business logic”.

But I agree, just having a custom structure that does not provide a safe wrapper around this would be sacrificing standard guarantees.

NIckGeek 50 minutes ago [-]
You can make a wrapper type that abstracts the offset lookup logic with a safe interface. If it's a transparent struct then rust will compile it away into nothing but you still get the abstraction in your code.
afdbcreid 6 hours ago [-]
> I can't help to think that the approach of joining several distinct list into a single one in some way undercuts Rust's safety guarantees.

Not really. You just need to make the underlying fields private and provide methods to get slices to the data you need.

vsgherzi 9 hours ago [-]
you could always do a .get into the vector and handle the error, it doesn't necessarily need to panic.

Thank being said in this case it should be impossible to index out of bounds so maybe a panic is warented.

pocksuppet 6 hours ago [-]
It's the exact thing Rust is made to protect against, on a more local scale. Every memory corruption bug is just an out-of-bounds index that wasn't protected against.
bvanheu 5 hours ago [-]
is dangling pointers reuse memory corruption bug from out of bound index?
FpUser 9 hours ago [-]
Tools exist to serve us, not the other way around.
asgraham 7 hours ago [-]
Sure, and usually one of the ways Rust serves us is with safety guarantees.

Which isn’t to say this optimization is a bad idea, just to say it’s sort of a straw man to imply coding in Rust to take advantage of safety guarantees is “serving Rust”

ww520 1 hours ago [-]
Not sure what they use to hold the cache key and entry. If a hashmap is used, then a radix tree (adaptive radix tree) would be better in saving memory space. Most of content of the qname field of the CacheKey is hostname, like www.site.com. The reverse version com.site.www fits nicely in navigation path of a radix tree. The common prefixes like "com." are shared and compressed in the parent nodes of the tree.

Even a BTree with compressed prefix keys can save space in the qname.

BikiniPrince 4 hours ago [-]
Funny thing about cloudflare. I have a dns warming script that uses their top 1k or 10k addresses. Then when my master starts up it warms the entire cache. Everything else uses memcache so the cluster is nice and toasty. As far as I can tell no one else releases domain statistics like them.
Dylan16807 1 hours ago [-]
So they optimized from Vec to Box, but they're still using Box all over and spending 16 bytes on it? The things they're boxing need 2 bytes for length, and their memory use is low enough that they could cram the pointers into 4 bytes. Trying to pack that into 6 bytes is probably too much fuss for the benefit, but I see no reason to use more than 8 bytes.
1saadcodes 5 hours ago [-]
We're finally seeing more appreciation for this kind of engineering. Not everything needs to be solved by throwing more hardware at the problem
bhouston 9 hours ago [-]
I've run into issues with using public wifi when I override my MacBook's DNS server to 1.1.1.1 or 8.8.8.8. I believe this is because captive portals require custom resolution of the name captive.apple.com. And external DNS servers will not resolve that correctly to the local gateway's authorization page.
MayeulC 8 hours ago [-]
AFAIK (at least it worked like that some 10 years ago) the captive portal just intercepts the HTTP page load and inserts its own content (most often a 302). So it just has to be a http web page. Firefox uses http://detectportal.firefox.com/canonical.html

Relevant support page, though light in details: https://support.mozilla.org/en-US/kb/captive-portal

Edit: ah, yes, DNS can be hijacked too (requires intercepting outgoing traffic on port 53 therefore incompatible with DoH), that may require fewer computing resources. Still need http otherwise the server cannot use the correct cert chain.

Edit 2: Wikipedia says both methods are used: https://en.wikipedia.org/wiki/Captive_portal and also mentions RFC 8910. I suspected something like that existed, hence my initial disclaimer.

My point was: that domain is not treated any differently from other domains.

comprev 6 hours ago [-]
I've had reliable success by using http://neverssl.com to force a basic HTTP connection for kickstarting a public WiFi portal login, although I have to disable NextDNS (iOS) too.
bpicolo 2 hours ago [-]
I use good ol example.org
Sohcahtoa82 4 hours ago [-]
The ironic part of neverssl.com is that it does indeed now support SSL.
fc417fc802 7 hours ago [-]
Can we take a minute to appreciate how utterly broken this state of affairs is? The dogged over centralization of DNS is an endless source of problems.
brians 8 hours ago [-]
That’s a Mac bug if so—it should be always using dumb udp/53 for captive detection, not some fancy DoH thing.
didgetmaster 1 hours ago [-]
Why do people seem to think that optimization is something you only have to deal with once the software scales so much that 100s of TB of memory or disk space (or thousands of hours of processing time) are being wasted.

It is almost like nobody even thought during the design phase about what might happen down the road.

This is why so much software is bloated and often buggy. Just gets something that half-way works out the door ASAP and worry about the rest later (too often, never).

jacquesm 59 minutes ago [-]
It can be quite hard to predict where particular usage patterns will take a piece of software under extreme load, especially with things that have lots of internal state. Obviously when you get to spend 100 T or more the pay off of an optimization is much larger than what it is in the case of 1T or less, and your typical developer is not going to have that kind of memory even in aggregate to play with. I tend to be forgiving when it comes to watching software bloat that I did not cause myself (and yet, I'm frustrated that Ubuntu's start-up greeting message takes a whopping 500 M).

In the case of internet infrastructure I don't think there was anybody even up to the year 2000 who had any idea of how bit this was going to be. And even now we have IPV4 and lots of legacy to deal with. Cloudflare is not my favorite company, let's put it like that, but in this case they show how the sausage is made and I think that should be applauded. Much better than 'why were down again for X hours'.

edflsafoiewq 7 hours ago [-]
General theme: A programming language's native in-memory object format is typically optimized for random access, uniformity, and mutability (fields at fixed offsets, etc). Serialization formats for network or disk tend to be designed explicitly to be more compact. But you can design your own in-memory representation too, with the properties you need.
kccqzy 5 hours ago [-]
That’s the old school of thought. These days, designers of newer serialization formats realize that designing a more compact format doesn’t really buy much on modern CPUs and modern networks. See for example Cap’n Proto (whose inventor, kentonv, also works at Cloudflare) and flatbuffers.
inigyou 47 minutes ago [-]
That's also the ancient school of thought, before compression was viable.
0xAstro 8 hours ago [-]
It's weird that it took so long for these trivial optimizations but it might just be that they were working on optimizing other stuff.
sergq 8 hours ago [-]
this applies to more than DNS caches. In 1998 I mailed Microsoft a proposal to replace search engine crawlers with a push-based filesystem monitor (detect change → extract → compress → push to index). Got a 5-line rejection letter. They built the same thing 20 years later as IndexNow. Full story with the original letter: https://dev.to/andrew_vl/in-1998-i-proposed-push-based-searc...
ManBeardPc 4 hours ago [-]
The Record struct contains rtype and data where RecordData is a tagged union. Aren’t those two always in sync? Not a DNS expert, just wondering if this is redundant or there is a reason both are there. Doesn’t matter anymore if they store it already serialized but I would be interested why it was this way.
9bot 9 hours ago [-]
The most interesting result to me is that the richer parsed representation was not necessarily the faster one. If the hot path is mostly “read from cache and serialize back to DNS,” parsing everything upfront only to serialize it again can become unnecessary work and hurt locality....
pocksuppet 6 hours ago [-]
> 56% A records, 25% AAAA, and 19% TXT

And they say nobody uses IPV6.

shric 5 hours ago [-]
It’s finally gaining some traction…

https://www.google.com/intl/en/ipv6/statistics.html

hnav 4 hours ago [-]
no doubt because of scraping and the cost of IPv4
rfgplk 8 hours ago [-]
Frankly weird that they were resorting to high level containers for this in the first place. Also, this line struck me as odd

> Big Pineapple uses jemalloc, an allocator designed for multithreaded, allocation-heavy workloads.

jemalloc multithreaded performance is actually poor(ish) compared to other modern allocators, which makes it a weird choice. But even weirder is why they're even using an allocator in the first place compared to a va MAP_ANON | MAP_NORESERVE arena carveout approach? You can also do punning that way too, which I'm not even certain if Rust supports?

jandrese 36 minutes ago [-]
An approach like that would be at constant war with the borrow checker in Rust. Apparently it is possible but there is enough friction that these guys went a different route.
cobalt 4 hours ago [-]
Rust supports punning via pointer casting, but you'll want to use #[repr(C)] on any data types used
senderista 7 hours ago [-]
I would also have instinctively reached for a large VM reservation to exploit demand paging. I have used that pattern a lot in C++ but not in Rust, so I don't know how difficult it would be to implement there.
superze 4 hours ago [-]
How much is this in euro or do we measure money in ram now?
inigyou 45 minutes ago [-]
Currently $15 per GB, he saved Cloudflare $1,500,000 and got exactly $0 bonus. He must really believe in cloudflare's vision (global enshittification). In related news, three times today Cloudflare told me that I'm a bot and shall not pass - not that it needs to check if I'm a bot before it lets me pass.
cristaloleg 6 hours ago [-]
Obvious question: why wasn’t this done earlier? It looks like all the data was already available. At THAT scale, reducing memory usage is a must-have, not a nice-to-have. Weird.
sophacles 6 hours ago [-]
Cloudflare talks about having datacenters in 300+ cities. Presumably they have at least a few servers per datacenter. They saved 130 servers worth of memory... not even the minimum number of servers they have (seriously though, they probably have a LOT of servers)... a few GBs of memory per server running the service. At that scale this is a nice-to-have.
yieldcrv 6 hours ago [-]
probably agents going through tech debt or finding wins

every dept knows what they could do with more budget, the budget for those things just never comes

now agents have utilized budget more effeftively, unbottlenecking many things, including engineering blogs

OptionOfT 9 hours ago [-]
> we store the records as a single Box<[u8]> containing each record encoded as a 2-byte length prefix followed by its raw bytes.

Interestingly this is exactly how netlink works-ish: https://manpages.ubuntu.com/manpages/focal/man3/netlink.3.ht...

You start, get the type & length, and then that is how many bytes you read.

Some issues with that when you deserialize, from a raw stream in to `[u8; 4096]` buffer, the alignment is only guaranteed to be on 1 byte, not 4 bytes.

In practice it is 4 bytes, but if you run those tests with Miri, you'll get yelled at. So the fix there is to declare the buffer with a type that mandates the alignment of the largest type that you're going to be deserializing.

So then you start your buffer as follows: `[u32; 1024]`, and with `slice::from_raw_parts` you get to turn that into `[u8; 4096]` with the expected alignment.

As an exercise I wrote a streaming parser for netlink, the current existing package serializes everything, all at once.

jandrewrogers 4 hours ago [-]
This kind of encoding[0] is ubiquitous in networking protocols. It scales down to small silicon well and enables the receiver to estimate resource requirements or skip parts of a serial byte stream without storing it in memory first. These encodings usually aren't aligned by design.

[0] https://en.wikipedia.org/wiki/Type–length–value

pocksuppet 6 hours ago [-]
It's called TLV encoding - tag/length/value. It's very common in all sorts of network protocols and serialisation formats. It allows you to skip unidentified tags. Sometimes, like in the PNG file format, there's a fixed bit in the tag that tells you whether it's safe to skip or if you have to reject the whole thing because you don't understand this tag.

Hey dang can I get my rate limit turned off pretty please?

dshat 9 hours ago [-]
I'll buys some spare RAM you now have. I only need 64GB.
squirrellous 3 hours ago [-]
I wonder at their scale, why wouldn’t it make sense to store the entries lightly compressed in memory?
mu54 5 hours ago [-]
The Art of Production.
varispeed 6 hours ago [-]
Now put the 100 terabytes of memory back to the market. Stop hoarding RAM.
HDBaseT 3 hours ago [-]
DNS is important and 100TB of RAM is effectively nothing.
kevinbaiv 4 hours ago [-]
[dead]
cpriest 7 hours ago [-]
[dead]
dumbotronz 5 hours ago [-]
[dead]
aaron695 3 hours ago [-]
[dead]
MagicMoonlight 8 hours ago [-]
[dead]
mannyv 9 hours ago [-]
One question the article doesn't answer is: why are they cacheing at all? If your cache is that big it isn't a cache. How much bigger is the dataset in question? There are 250 billion entries. Assuming 80/20, that implies 1.25 trillion records?

What's the speed of service/response time relative to the data source?

At that point it might be enough to replace your multiple caches with fewer in-RAM databases?

It's an interesting problem.

bastawhiz 9 hours ago [-]
Maybe I'm misunderstanding, but this powers 1.1.1.1, it doesn't front an internal dataset. A cache miss hits a nameserver. Which is to say, the dataset is "every DNS record in the world"
auspiv 8 hours ago [-]
I think the question is probably more along the lines of - why not do a database with 100 TB of storage/records instead of a cache? tomato / tomato.. especially with smart caching in front of database. 100TB of flash is a good bit cheaper than 100TB of memory
ecnahc515 8 hours ago [-]
Because it would be slower and have different scaling requirements than the ones they want.
pocksuppet 6 hours ago [-]
It's not 100TB of data. It's probably 50 GB of data on each of 2000 servers. Because it's a cache. What is the point of a central cache if it's as slow to access as the original data?
inigyou 44 minutes ago [-]
TFA gives numbers closer to 5GB.
fc417fc802 7 hours ago [-]
I'm no expert but presumably all of throughout, latency, and churn. DNS is approximately a giant KV store where the typical record has a TTL of ~5 minutes.
robotresearcher 7 hours ago [-]
This is smart, task-specific caching in front of database.
seiferteric 9 hours ago [-]
You have to cache, cloudflare doesn't know all the records ahead of time, they have to do recursive lookups to the authoritative servers that own the records and that is only good for the period of the TTL of the record. There is no "global" DNS record database or something like that.
pbhjpbhj 8 hours ago [-]
>that is only good for the period of the TTL of the record.

Not really, TTLs are often short, but IPs might not change for years.

You can probably generate your own TTL, at scale, and avoid many DNS requests.

fc417fc802 7 hours ago [-]
Why would anyone want to use a DNS resolver that tampered with records on a large scale? The TTL is intentionally set by the originator of the record.

Or alternatively, if you don't tamper why would I want to use a service that serves stale data?

robotresearcher 7 hours ago [-]
Every distributed system serves stale data.

You can define away ‘stale’ by picking a consistency model, but look inside the consistency machinery and you will see fresher data you aren’t allowed to have yet.

4 hours ago [-]
otterley 8 hours ago [-]
In DNS, the owner of each record has full control over its TTL. Intermediary DNS servers are required to honor them and are not permitted to replace TTLs with their own.
dizhn 7 hours ago [-]
DNS servers do in fact do that but it would not be a good look for the world's largest DNS provider.
inigyou 43 minutes ago [-]
I don't think cloudflare cares about how it looks, also I think Google is bigger.
ButlerianJihad 7 hours ago [-]
Actually that is not true. The IETF has expanded the definition of “TTL” and explicitly permits resolvers to serve “stale” RRs beyond their expiration time.

https://www.rfc-editor.org/info/rfc8767/

As a corollary, there is obviously no floor on refetching unexpired RRs, of course, except for efficiency concerns.

seiferteric 7 hours ago [-]
That's only when the authoritative server cant be reached though
pbhjpbhj 7 hours ago [-]
You are obliged to pass on the TTL, you're not obliged to cache according to it.

At least in my country (UK) I know of no law relating to DNS caching.

Why throwaway perfectly good data every few minutes that is only modified every couple of years, just so someone can move their domain quickly when they eventually wish to? It is my contention that a [caching] DNS service can do far better. Trusting user (domain owner) input blindly is not for me.

otterley 7 hours ago [-]
It's not some sort of public law with public enforcement, but it is in the RFCs that govern the protocol.

I should be a bit clearer here; the TTL is an upper bound on how long it can be cached. Caches are free to consult more frequently but not less frequently. That said, out of respect for upstream cache operators and authoritative servers, most DNS caches honor TTLs as best they can.

inigyou 43 minutes ago [-]
The IETF isn't the internet police. You don't have to follow its advice.
seiferteric 8 hours ago [-]
then they would be breaking DNS at scale.
6 hours ago [-]
toast0 8 hours ago [-]
It's a recursive resolver. The global DNS dataset is not something you could collect to serve directly vs caching from observations.

The data source is authoritative name servers operated by third parties, some of which are slow on their own, some of which are behind slow or lossy networks. Origin response times vary between probably 1 ms and 2 seconds +/- origins that never respond.

eggnet 9 hours ago [-]
They’re adding the cache consumed across all of their servers. It’s not one giant deep cache.
otterley 8 hours ago [-]
The simple answer is that if you didn't cache, DNS traffic would skyrocket, and the load would pile up on the authoritative servers, which were intended to be small, and during the early days of the Internet, were frequently on bandwidth-constrained links.

DNS is designed to distribute query load to the edge as much as possible, and that's enabled by caching. It just so happens that "the edge" is now becoming concentrated among a small set of providers because they wanted to make a business out of it.[1] They knew that this would be expensive going in, though.

[1] Nobody has to use 8.8.8.8 or 1.1.1.1. Most people can use their ISP's cache or a local cache instead without any noticeable difference in behavior.

fragmede 7 hours ago [-]
The problem is there is a noticable difference in behavior because the ISP cache is overloaded so queries take longer. Sure, that's not everyone's experience, but there's a reason people chose to use alternate servers.
eviks 10 hours ago [-]
> Once we store a DNS response in the cache, however, we never modify it again. The capacity field serves no purpose, but still costs 8 bytes per Vec

Were there no design discussions/reviews when the system was setup to catch trivial things like this?

r3trohack3r 8 hours ago [-]
Rob Pikes 5 Rules of Programming:

Rule 1. You can't tell where a program is going to spend its time. Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you've proven that's where the bottleneck is.

Rule 2. Measure. Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest.

Rule 3. Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don't get fancy. (Even if n does get big, use Rule 2 first.)

Rule 4. Fancy algorithms are buggier than simple ones, and they're much harder to implement. Use simple algorithms as well as simple data structures.

Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.

https://web.archive.org/web/20260314210910/https://users.ece...

eviks 8 hours ago [-]
> Data structures, not algorithms, are central to programming

So you agree that they should've designed the system to use the appropriate data structure from the beginning?

ecnahc515 8 hours ago [-]
Notice rules are ordered. You don't optimize until you know you need it. They started with a data structure they though would be fine. Clearly it was fine since it worked and they decided it was later worth optimizing.
8 hours ago [-]
win311fwg 8 hours ago [-]
The existence of 1.1.1.1 speaks to a much larger design problem. If you want to talk about what should have been done, you need to step much, much further back.
eviks 7 hours ago [-]
I don't want to step back and go off topic
win311fwg 7 hours ago [-]
"Should" cannot be evaluated in a vacuum. The only thing that would be off-topic is pretending that it can be.
perching_aix 6 hours ago [-]
> Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest.

Genuine question, is software performance really linear like that, that one can and should only fight the tightest bottleneck, one workload at a time? Never really sounded right.

It also sounds like the typical sleight of hand where the difficult bit is simply laundered a layer up, in this case the choice of what workload one investigates.

lbriner 10 hours ago [-]
It is often not worth optimising in the early days. You don't know how popular it will become, you might not know how many DNS records you will hold, it was possibly written in an earlier language and ported as-is.

At the point someone queries the 100TB of RAM, then maybe it is worth revisiting but even that has risks. You have to design the migration path, have fallback mechanisms etc.

eviks 9 hours ago [-]
It's also often that you can avoid all those future migration/fallback risks and pains if you invest a little bit of design thinking upfront.

So how would you decide which path to take in situations like this?

suriyaG 9 hours ago [-]
It only looks super obvious in hindsight and the well explained blog post. when a team of 5 is tasked with getting a completely new DNS up at the scale and integrate well with cloudflare.

if you spend cycles on nitty gritty opinions like this time to market goes out further and further out. some napkin math, 130 gen13 servers cost "only" ~$2.6M. relative to the importance of the 1.1.1.1 and the market at the time. that is nothing to cloudflare.

this is not to say good system design does not matter. it very much does, but making that call at that time would've butchered the prodcut very much similar to google+, youtube etc.

eviks 8 hours ago [-]
This one also looks pretty obvious "in foresight" (using the same tools that existed back then. Maybe owner dedupe might be less obvious and require a bit of knowledge and probing into actual data, but for rw vs ro you are fine knowing nothing?) and you forgot the napkin math re. how much your precious "time to market" would have been delayed by.

It's also not nothing, otherwise it would never be optimized away now, but left as is. After all, wasting time on optimization delays "time to market" for other useful features.

I also don't get the reference to YouTube, it's a very successful product, how was it butchered by good system design???

sophacles 5 hours ago [-]
Imagine you're an engineer at cloudflare, an 8 year old (at the time of launch of 1.1.1.1) company. The company is wildly popular and any service launched is going to have a lot of traffic and a lot of attacks right away. Any problems with it are going to embarass the company a lot.

You're tasked with making a DNS caching recursive resolver that can operate at a large scale and will be run on thousands of servers each of which has a lot of GBs of ram.

You are given some period of time to build this and make it production ready. How do you spend your time:

* Focusing on making sure that the resolver works correctly?

* Focusing on make sure that it actually provides improved DNS performance for internet users?

* Handles an very large number of record requests/s?

* Saves a few GB of ram per server?

There are tradeoffs to consider. RAM is cheap, even at today's prices RAM is not the most expensive thing that can go wrong in such a scenario. Having the responses be slow or incorrect is a far more expensive problem. A good engineer would pick a simple data structure that has the right shape but might not be optimal in footprint to focus on correctness and response time. The few extra GBs of RAM per server can be dealt with later.

When building things at scale you want to make sure it works correctly, fails correctly, and does the thing quickly before worrying about reducing resource consumption. I've never seen a project fail on Vec<T> vs Box<[T]> memory differeneces, or even on a few GBs of RAM usage per instance. I have seen them fail on "one wierd corner case of correctness" though, and on poorly thought through failure modes.

toast0 24 minutes ago [-]
> The company is wildly popular and any service launched is going to have a lot of traffic and a lot of attacks right away.

Doesn't this also inform you that your cache will be very large, so you shouldn't use growable structures with slack space when cache entries won't grow; slop space reduces the size of your cache. And also that the query volume will be high so the cached data should require as little work as possible before returning data; spending time marshalling response data on every cache hit increases response time and decreases capacity.

mhitza 10 hours ago [-]
Premature optimization argument fits right in. Now that memory is up to 10x more expensive it is worth considering optimizing programs with large memory footprint.
toast0 9 hours ago [-]
Using obviously better data structures the first time isn't premature optimization.
mannyv 9 hours ago [-]
There was a reason for that field, but that reason never panned out.
eviks 9 hours ago [-]
Could you point to that reason?
mayli 7 hours ago [-]
Maybe it's not that obviously better when it's impltd.
eviks 10 hours ago [-]
How does that fit? What would be the evil of not wasting memory for many years at 1x?
jgrahamc 10 hours ago [-]
One of the "evils" of premature optimization is how much time you spend on the optimization vs. the benefit you get from it. If your goal is correctness and shipping fast and you're not memory constrained then spending time using the least amount of memory is a waste of time specifically because you want to ship fast.

Another interesting thing that happens is you don't necessarily know what form your actual optimizations will need to take. Later when your systems grow you discover the suboptimal parts you hadn't optimized for.

Very early on at Cloudflare I worked on part of the DNS infrastructure that took DNS records from the UI and got them in a state for actual authoritative serving. The system had been constructed anticipating Cloudflare having millions of customers with unique domains, but it had not been constructed for a single customer with a single domain with millions of records. This caused a periodic slow down in DNS record updating while the system churned on that one customer.

In a different job I worked on a piece of optimization software that needed to keep track of "node" A is reachable from node "B". This had been implemented as a matrix (literally a malloced NxN matrix of ints storing 0 or 1) which worked really well for small systems. But you'd be out of memory really fast on a large project. I replaced the matrix with a hash table and all was good because the matrix was actually really sparse.

stickfigure 9 hours ago [-]
Absolutely true, but I will say that LLMs have changed the equation somewhat.

With a rather short prompt, claude/codex will take your code, write a harness, profile it, build experiments, profile those, and give some pretty solid advice which one to pick. Then integrate the changes. It's the kind of goal-directed, bite-sized job that LLMs excel at. Extremely low-commitment.

Except for the whole "making changes in production at scale" problem, of course.

gbear605 10 hours ago [-]
Engineers are expensive, especially good system engineers who are trained in your code base. Very possible that this just hadn't gotten to the top of the priority list.
eviks 9 hours ago [-]
I don't understand why you need training on your code base to design a cache format for read only vs rw workloads, but anyway yours is a comment about neglect, not the "evil" that would happen if you did that design
Spooky23 9 hours ago [-]
I see your point but disagree. Engineering is about constraints. Time, materials, labor, scope.

The “evil” of premature optimization is that it’s a misapplication of priority. If I have an acute medical problem that needs attention, it’s not the right time to talk about chloresterol and statins, get my broken leg set.

There’s always a tension between engineering management who needs to deliver a solution to the business and engineers who want to deliver a beautiful object.

win311fwg 9 hours ago [-]
> I don't understand why you need training on your code base to design a cache format

Because anyone willing to come in just to design your cache format is going to expect payment that is many multiples more than the engineers you already cannot afford? Long-term employees cost less, which brings them closer to being affordable, but you have to be able to keep them busy for long periods of time to realize that reduction in cost. A engineer who doesn't understand your codebase isn't going to be useful for very long.

eviks 9 hours ago [-]
You explained why it's beneficial for other workloads, but the original point was about this specific design
scott_meyer 9 hours ago [-]
Discussing trivial optimizations is a waste of valuable design time. You're never going to "forget" an optimization. The running system will remind you when the optimization is actually needed.
ratmice 8 hours ago [-]
Boxed slice isn't really the most well known type/optimization, There usually aren't that many vec's that it makes a big difference.
micromacrofoot 10 hours ago [-]
it was working so no one thought to check
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 03:18:53 GMT+0000 (Coordinated Universal Time) with Vercel.