What Wait Why: Heroku Doesn’t Want You to be Naked
Tags: webdev, devops, learning, meta
Published: 2018-11-19 21:05:03

---
title: What Wait Why: Heroku Doesn’t Want You to be Naked
published: true
description: why you should probably use a www 
tags: webdev, devops, learning, meta
cover_image: https://i.imgur.com/5vH8iLu.png
---

`www.` is a subdomain. It took me forever to realize that.

When reddit switched to their new UX, they created an `old.reddit.com` that you could use to go back if you _really_ wanted ~~a sane usable experience~~ the crusty old thing. 

For the longest time, I thought it was broken. I’d go up to my address bar and in between the `www` and the `reddit.com`, I’d put `.old` so you’d wind up with:

```
https://www.old.reddit.com
```

That would cause my browser to panic and hit me with an SSL error:

![ssl error](https://i.imgur.com/v9xq6ya.png)

My mental picture of `www`  was not as a subdomain like `old.` or `blog.`, but as “part of that junk in the beginning.”

Every site has `www` right? It's just like `https://` or whatnot right? 

# Some Sites are Naked 😱

If a domain doesn't have a subdomain (ex: `dev.to`) we say it's a _naked domain_. 

A lot of sites choose to live in their birthday suit for the same reason that I couldn't figure out how to go to ~~better~~ old Reddit: www is weird.

Most users don't understand how www works or why it's there. Browsers autocomplete and [even hide the www](https://www.theregister.co.uk/2018/09/07/google_kills_www/) nowadays. Many sites that use www will redirect their naked domains to their www version anywhoo, so most folks forget it exists. 

From the perspective of the user, www feels like some Web 1.0 jazz, complete with fire gifs and hit counters. 

![web1.0](https://i.imgur.com/7CKgQ2U.png)

# We need more than just "A" record

If you've read [my last post](https://dev.to/flaque/dns-and-an-evolving-political-crisis-a-saga-of-the-cat-domain-4jh1), you know that domains are managed with **Resource Records**. 

When we're setting up a site, there's two common ones that we could choose to use: `A` records and `CNAME` records.

With an `A` record, we specify a hard-coded IP for the "Apex" or root of domain. For example, `dev.to` (as of this writing) has the A records that look like this:

```
dev.to.			299	IN	A	151.101.2.217
dev.to.			299	IN	A	151.101.194.217
dev.to.			299	IN	A	151.101.66.217
dev.to.			299	IN	A	151.101.130.217
```

# Big Sites need Big Clusters

Behind the scenes of your favorite cat-picture-providing websites, a miracle is happening. A rotating centrifuge of computers is picking up your interweb searches. Computers blink in and out of existence for pennies on the dollar. Beeps boop. The world spins. 

Most "big" sites run on multiple computers that operate independently of each other. If a site suddenly gets a tremendous amount of traffic all at once (like [Segment](https://segment.com/) does during Cricket games), new computers get spun up automatically to handle the load.

Those computers need their own IP addresses so we can start sharing traffic. Many managed cloud providers like Heroku, will do this all for you. 

You give them the code, they monitor your traffic and then 3D print a preconnected macbook with a Heroku sticker to handle your spikes. Or something like that; I dunno, I'm not an expert. 

# A Becomes Cname

You can add a whole bunch of A records to your domain to support a bunch of different servers but ultimately, an A record cannot support dynamic ips.

**You can't just add a new IP and expect it to work.** DNS can take up to 24 hours to fully propagate!

By the time your site can tell the world about your new machines, your spike is over. 

Instead, what we could do is use a `CNAME` record here. CNAMEs are special because they don't need to point to an IP address, they can point to another domain:

```
app.segment.com.	252	IN	CNAME	segment.com.
```

That lets us shove the problem of new IPs onto our host provider (like Heroku). In fact, this is [exactly what Heroku tells you to do in its docs](https://devcenter.heroku.com/articles/apex-domains).

# CNAME is a prude

According to the DNS spec, you can't use a CNAME on a naked domain. 

So we're gonna need to bust out our ✨**subdomains.**✨ What's the most common subdomain for this problem? 

![www yaaaa](https://i.imgur.com/qCl7Dpz.png)

# Woah, woah, woah, but DEV is naked

I know, it's terrifying. It's probably not _that_ big of a concern though. Dev is mainly shipping static content and it's doing it over a CDN.

That `151.101.x.x` ips we saw before? Those are [Fastly](https://www.fastly.com/) IPs. If I had to guess, each of the four IPs are [Anycast IPs](https://en.wikipedia.org/wiki/Anycast). This is a bit of a workaround some CDN services like Fastly offer, but according to the [Fastly docs](https://www.fastly.com/), **it's more expensive and less performant than just using a CNAME for www**. 

# So wait, should dev change?

Probably not. There's likely a whole host of issues that could be caused by changing the domain at this point. Plus, Dev probably _should_ be concerned about url usability. 

Computers get faster over time, but usability, [usability never changes.](https://d1u5p3l4wpay3k.cloudfront.net/fallout_gamepedia/f/f2/War_Never_Changes.gif) 

But when you're setting up your site, you should carefully consider the `www`. It may lead to headaches in the future.