·10 min read

How DNS Resolution Became Our CI/CD Bottleneck at 600+ Daily Builds

When Jenkins scaled from 50 to 600+ builds per day, DNS resolution failures brought everything down. Here's how Linux networking knowledge saved us.

Builds started failing at random with network timeouts. Retry, green. Retry the next one, red. It took us a while to admit what it was, because it's always the last thing anyone suspects: DNS.

The Growth Trajectory

Six months ago, our development team was lean. 10 engineers, a handful of microservices, maybe 50 builds on a busy day. Our Jenkins setup was straightforward:

  • 3 executor nodes with 4 executors each (12 total concurrent builds)
  • Builds pulling from GitHub, DockerHub, and internal artifact repositories
  • Average build time: 8-12 minutes
  • Everything worked smoothly

Then we raised funding. The team doubled, then doubled again.

Month 1:  10 engineers → ~50 builds/day
Month 3:  20 engineers → ~150 builds/day
Month 6:  40 engineers → 600+ builds/day
 
Jenkins scaling:
Month 1:  3 nodes, 12 executors
Month 6:  8 nodes, 32 executors

We added more Jenkins executors. We upgraded our infrastructure. We optimized our pipelines. On paper, we had the capacity.

But the builds started failing.

The Symptoms

At first, it was sporadic. A build would fail with a network timeout. Retry it, and it worked. "Transient network issue," we thought. Move on.

Then it got worse.

The Error Messages

Error cloning repository: Could not resolve host: github.com
Timeout while connecting to registry.hub.docker.com
Failed to fetch package: Temporary failure in name resolution
curl: (6) Could not resolve host: api.internal.company.com

All DNS-related. All intermittent. All concentrated during peak build times (9am-11am, 2pm-4pm).

The Pattern

We started tracking failures:

Time Range       Builds    Failures    Failure Rate
08:00 - 09:00      45         2           4.4%
09:00 - 10:00     120        18          15.0%
10:00 - 11:00     145        27          18.6%
11:00 - 12:00      95         8           8.4%
12:00 - 13:00      50         1           2.0%
13:00 - 14:00      65         3           4.6%
14:00 - 15:00     135        22          16.3%
15:00 - 16:00     140        25          17.9%

Clear correlation: more concurrent builds = more failures. All DNS-related.

The Investigation

Standard debugging didn't show much. Network connectivity was fine. DNS servers were healthy. A dig from any single node worked perfectly every time we tried it.

So we stopped looking at whether DNS worked and started looking at how much of it we were doing.

DNS Query Explosion

Each build was making dozens of DNS queries:

  • Cloning from GitHub: github.com
  • Pulling Docker images: registry.hub.docker.com, auth.docker.io, production.cloudflare.docker.com
  • Downloading dependencies: npmjs.org, pypi.org, maven.org, etc.
  • Internal services: api.internal.company.com, artifacts.internal.company.com
  • External APIs: various third-party endpoints

Conservatively: 20-30 unique DNS queries per build.

Do the math:

Peak concurrent builds: 32 (all executors running)
DNS queries per build: ~25
Query frequency: every few seconds during active build phases
 
Peak load: 32 builds × 25 domains = 800+ DNS queries
Duration: sustained for 8-12 minutes per build wave

We were hammering our DNS infrastructure with thousands of queries per minute.

Checking the DNS Setup

On our Jenkins executors, /etc/resolv.conf looked like this:

$ cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
options timeout:2 attempts:3

Every DNS query was going out to Google's public DNS. No caching. No local resolver.

With 2-second timeouts and high query volume, we were hitting timeout limits under load. Queries were queuing, timing out, and failing builds.

How Linux Actually Resolves a Name

To fix it we had to stop treating DNS as a black box. When an application looks up a name on Linux, this is the path:

Application (curl, git, docker)
    ↓
glibc resolver (getaddrinfo)
    ↓
/etc/nsswitch.conf (determines resolution order)
    ↓
/etc/hosts (checked first if configured)
    ↓
DNS resolver (from /etc/resolv.conf)
    ↓
systemd-resolved OR traditional resolv.conf
    ↓
Upstream DNS servers (8.8.8.8, etc.)

By default, there's no caching at the OS level. Every query goes all the way to the upstream DNS server.

/etc/resolv.conf

This file controls the resolver's behavior:

nameserver 8.8.8.8      # Primary DNS server
nameserver 8.8.4.4      # Fallback DNS server
options timeout:2       # Timeout per query (seconds)
options attempts:3      # Number of retry attempts
options rotate          # Rotate through nameservers
options ndots:1         # Dots required for absolute lookup

The line that matters: timeout:2 with attempts:3 means a failed query takes 6 seconds minimum before giving up. Under load, these timeouts stack up, and a git clone or docker pull waiting on them eventually gives up itself.

systemd-resolved

Modern Ubuntu uses systemd-resolved, which provides some caching:

$ systemctl status systemd-resolved
● systemd-resolved.service - Network Name Resolution
   Active: active (running)

But the default cache is limited:

$ resolvectl statistics
Current Cache Size: 0
Cache Hits: 127
Cache Misses: 1843

Cache hit rate: about 6%. Not nearly enough for our use case.

Why No Caching?

Most CI/CD workloads are short-lived. Jenkins executors start build jobs that run for minutes, then stop. The OS-level DNS cache (even with systemd-resolved) didn't help us much because:

  1. Each build is a fresh process with no cache
  2. systemd-resolved's cache is limited (short TTLs)
  3. High concurrency means the cache keeps getting wiped

We needed a dedicated DNS caching layer.

The Solution: DNS Caching

We implemented a local DNS cache on each Jenkins executor using dnsmasq.

Why dnsmasq: it's small, the config is a dozen lines, and it does exactly one job here (cache and forward). We didn't need a recursive resolver, we needed fewer packets leaving the box.

Implementation

Step 1: Install dnsmasq

sudo apt-get update
sudo apt-get install -y dnsmasq

Step 2: Configure dnsmasq

Edit /etc/dnsmasq.conf:

# Don't read /etc/resolv.conf for upstream servers
no-resolv
 
# Define upstream DNS servers explicitly
server=8.8.8.8
server=8.8.4.4
server=1.1.1.1
 
# Cache size (default is 150, we increased it)
cache-size=10000
 
# Don't forward queries for plain names (security)
domain-needed
 
# Don't forward reverse lookups for private IP ranges
bogus-priv
 
# Listen on localhost only
listen-address=127.0.0.1
 
# Log queries (for debugging, disable in production)
# log-queries

Step 3: Update /etc/resolv.conf

Point the system resolver to localhost:

# Drop the immutable flag in case it was set before
sudo chattr -i /etc/resolv.conf
 
# On Ubuntu, /etc/resolv.conf is usually a symlink into /run/systemd/resolve/.
# Remove it, otherwise tee writes through the link into /run and chattr fails.
sudo rm -f /etc/resolv.conf
 
# Write a real file
sudo tee /etc/resolv.conf > /dev/null <<EOF
nameserver 127.0.0.1
options timeout:1
EOF
 
# Make it immutable so nothing (DHCP hooks, netplan, resolved) rewrites it
sudo chattr +i /etc/resolv.conf

Order matters with Step 4: dnsmasq can't bind port 53 while systemd-resolved's stub listener holds it on 127.0.0.53, so stop resolved before you start dnsmasq. If systemctl start dnsmasq fails with "Address already in use", that's why.

Step 4: Disable systemd-resolved (it conflicts)

sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved

Step 5: Start dnsmasq

sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq
sudo systemctl status dnsmasq

Verification

Test DNS resolution:

$ dig github.com @127.0.0.1
 
;; Query time: 45 msec  (first query - cache miss)
 
$ dig github.com @127.0.0.1
 
;; Query time: 0 msec   (cached!)

Check dnsmasq cache stats:

sudo kill -USR1 $(pidof dnsmasq)
sudo tail -20 /var/log/syslog
 
# Output shows:
# cache size 10000, 0/847 cache insertions re-used unexpired cache entries
# queries forwarded 1243, queries answered locally 8621

Cache hit rate after deployment: 87%.

The Results

The impact was immediate.

Metric                          Before      After       Improvement
-----------------------------------------------------------------
DNS query latency (avg)         45ms        0.5ms       90x faster
DNS timeouts per day            180         3           98% reduction
Build failure rate (peak)       18%         0.8%        95% reduction
Average build time              11.2min     9.8min      12% faster
Jenkins executor CPU (DNS)      8%          0.2%        40x less

Fixing the failures was the goal. The build time drop was a bonus we didn't expect: cutting DNS latency shaved 1-2 minutes off the average build. The 87% hit rate also meant 87% fewer queries leaving the executors, and when something DNS-related did go wrong, the dnsmasq logs showed it right away instead of us guessing.

Monitoring DNS in Production

After deployment, we added DNS monitoring to our observability stack.

We track:

# Cache hit rate
(queries_answered_locally / total_queries) * 100
 
# Query latency percentiles
p50, p95, p99 query times
 
# Timeout rate
dns_timeouts / total_queries
 
# Cache size utilization
current_cache_entries / max_cache_size

And alert on:

  • Cache hit rate drops below 70%
  • DNS timeout rate exceeds 1%
  • Average query latency exceeds 10ms
  • dnsmasq service is down

Plus a Grafana dashboard:

┌─────────────────────────────────────────────┐
│ DNS Performance - Jenkins Executors         │
├─────────────────────────────────────────────┤
│                                             │
│  Cache Hit Rate:        87.3%  ✓           │
│  Avg Query Time:        0.6ms  ✓           │
│  Timeout Rate:          0.04%  ✓           │
│  Queries/min:           1,240              │
│                                             │
│  [Graph: Query latency over time]          │
│  [Graph: Cache hit rate over time]         │
│  [Graph: Timeout rate correlation]         │
│                                             │
└─────────────────────────────────────────────┘

What We Learned

Monitoring had a blind spot

Our monitoring showed:

  • Network: healthy ✓
  • DNS servers: healthy ✓
  • Individual queries: working ✓

All true, and all useless. Nothing measured the volume: thousands of DNS queries per minute from 32 executors hitting the same two upstream servers. We added DNS-specific metrics after this. Volume matters, not just success rate.

What works at low scale breaks differently at high scale

A single build making 25 DNS queries? No problem. 32 concurrent builds making 800 combined queries, sustained over minutes? Problem.

At 50 builds/day we never thought about DNS. At 600 builds/day our silent assumption, "DNS resolution is fast and reliable", was wrong. We only reacted: added executors when builds queued, added resources when things slowed. Nobody asked "what happens at 10x?" If I had to do it again, the question I'd ask before scaling CI is simple: where does every build make the same external call over and over? DNS was obvious in hindsight. It should have been obvious in foresight.

Caching is infrastructure too

We think of caching for application data: Redis, Memcached, CDNs. The same logic applies to CI: DNS (dnsmasq, nscd), packages (apt-cacher-ng, a Docker registry pull-through cache), artifacts (Nexus/Artifactory). Every external dependency a build hits on every run is a future bottleneck.

Know the layer below you

Knowing how /etc/resolv.conf, the glibc resolver and systemd-resolved fit together is what got us from "random network flakes" to a fix. That's not esoteric sysadmin knowledge. When your builds fail and nobody can explain why, it's the difference between guessing and understanding.

Implementation Checklist

If you're running CI/CD at scale, here's what to check:

1. Measure your DNS query volume

# Watch DNS traffic live on a CI node
sudo tcpdump -i any -nn port 53 -c 100
 
# Rough queries-per-minute: count outgoing DNS packets for 60 seconds
sudo timeout 60 tcpdump -i any -nn 'udp dst port 53' 2>/dev/null | wc -l

With -i any on a Docker host, a query from a container can be captured on both docker0 and the uplink, so treat the number as an upper bound.

2. Check your DNS configuration

cat /etc/resolv.conf
systemctl status systemd-resolved
dig +trace example.com  # Verify resolution path

3. Test DNS under load

# Simple load test
for i in {1..1000}; do dig github.com > /dev/null & done
wait
 
# Monitor for failures or slowdowns

4. Implement DNS caching if needed

  • Install dnsmasq (or alternatives like nscd, unbound)
  • Configure appropriate cache size for your workload
  • Point /etc/resolv.conf to localhost
  • Monitor cache hit rates

5. Add DNS monitoring

  • Query latency (p50, p95, p99)
  • Cache hit rate
  • Timeout rate
  • Query volume over time

Alternatives to dnsmasq

We chose dnsmasq, but it's not the only option:

  • nscd: on most distros already, minimal setup. Less visibility into what it's doing, and it has a history of caching bugs.
  • systemd-resolved, tuned: already there on modern Ubuntu. We found its caching too conservative for this and didn't want to fight it.
  • unbound: a full recursive resolver with DNSSEC. Powerful, and overkill if all you want is a cache.
  • CoreDNS: the right answer inside Kubernetes. On plain VMs it's more moving parts than you need.

For a fleet of CI VMs, I'd still pick dnsmasq: simple, effective, lightweight.

The TL;DR

  • Team went 10 → 40 engineers, Jenkins went 50 → 600+ builds/day on 32 executors
  • Peak hours meant 800+ concurrent DNS lookups going straight to 8.8.8.8 with no local cache
  • Failures were intermittent, DNS-only, and tracked peak hours (up to 18.6% failure rate)
  • dnsmasq on every executor: 87% cache hit rate, 45ms → 0.5ms query latency, DNS timeouts down 98%, peak build failure rate from 18% to 0.8%
  • Monitor DNS volume, not just whether DNS works

It's not DNS. There's no way it's DNS. It was DNS.


A note on how this was written: I used AI to help with phrasing and structure. The tone, the opinions, the war stories, the code, and everything else here are mine.