tl;dr Buy an Edgerouter ER-X and configure it using these instructions
The problem: lag and ping spikes
We're probably all familiar with the terrible lag you can get when your home internet connection is congested. It could be a house mate downloading with bittorrent, netflix, steam, automated device updates....
It doesn't have to be this way, and in this post I'll explain what you can do by fixing a thing called "bufferbloat".
Measuring bufferbloat
First of all, you'll want to get a quick idea of how bad your ping gets when your connection is congested. To get a rough idea, run the DSLReports speedtest. Please use an ethernet cable, if you're on wifi or a powerline adapter, you're gonna have a bad time.
The bufferbloat score is directly related to your lag during congestion. Anything worse than A+ or A means you'll lag badly if your connection is congested.
Regardless of how fast your connection is you can suffer from bufferbloat. I've seen fiber 500/500Mbit connections with over 500ms of bufferbloat.
Bufferbloat is the enemy, and using the tips below, I took my bufferbloat score from a C to an A+.
How to fix it
There are basically two ways to get these improvements, the first one easy and the second one a little harder, but they both involve traffic shaping and QoS.
1. Buy a $50 Edgemax ER-X router.
2. Flash a router to OpenWRT/LEDE (could be your current one, but you might lose WiFI depending on the chip used in the router)
So first of all, buying an ER-X router:
It's cheap, it's great and it comes with some tools baked in to fight bufferbloat. Battle(non)sense made a great video about how to configure a router like this. In the video he uses the slightly more expensive ER-L, but for our use case the ER-X is both cheaper and faster. The instructions are the same.
Once you've done this, you'll have the 2nd best method of fighting bufferbloat. For bonus points you can go over to the Edgemax forums and get your hands dirty to install the best method of fighting bufferbloat, it's called "cake", because it's a piece of cake to configure. Cake also has an extra neat feature where it will fairly divide the available bandwidth between the devices using the connection.
The second option is to flash a router to OpenWRT/LEDE:
This is a custom firmware for your router and it has the bufferbloat fixes included. You might even be able to flash your current router to this firmware, but depending on the wifi chip used in your router, wifi might not work or work worse after flashing, so beware. Flashing instructions vary between models, but for quite a few routers you can just load the custom firmware in the current web interface of your router, easy!
Limitations
1. Traffic shaping is reasonably tough on the CPU in a router, depending on your connection speed you might need a beefier router to handle the speed. Here are some rough numbers for what a given router can handle in traffic shaping speed (total speed up+down, so a 200Mbit down, 20Mbit up connection would need 220Mbit/sec)
Edgemax ER-Lite: 70Mbit/sec (170Mbit/sec with some hacks)
Edgemax ER-X: 180Mbit/sec (220Mbit/sec using "cake")
Linksys WRT1200AC: 500Mbit/sec
Linksys WRT1900AC: 700Mbit/sec
2. If your internet speed varies due to a crappy ISP, you'll need to update the traffic shaping speeds to compensate. My ISP is currently so congested that I can only count on 100Mbit instead of 200Mbit download during some evenings. So I need to change my settings to compensate for this.
3. Your traffic shaping router needs to be the only thing directly connected to the internet. So if you have cable/dsl modem with built-in wifi you need to disable or not use this wifi signal, as it will bypass the traffic shaping. All your traffic must flow through the traffic shaping router. If your cable/dsl modem supports "bridge" mode, use that.
4. To keep the bufferbloat under control, you give up about 5-10% of your internet speed. I get 190Mbit down and 38Mbit up with the fixes enabled vs 200/40 with the fixes disabled. But I gladly make this tradeoff for a much more responsive connection.
P.S.
My connection without any fixes: No prioritization of download, upload and pings, so bittorrent is just as important as gaming traffic. 100+ms higher ping during congestion.
My connection with Cake traffic shaping: Prioritization of traffic depending on the type, 5ms higher ping during congestion.