Mastering Heroku #1

Happy Wednesday! I’m so excited you’ve joined me in this little experiment. My goal is to help you run your apps on Heroku faster, cheaper, and with more peace of mind. In the spirit of experimentation, let me know what you like and don’t like about the format and content, and we’ll iterate on it. Cool? Great, let’s dive in.

Spotlight…

I really enjoyed Brandur’s In Pursuit of Production Minimalism. Sound heavy? Honestly, it does get a little heavy, but stick with it to the “In ideas” list at the end. I’d heard of NIH (Not Invented Here), but NHH (Not Hosted Here) was new to me. 😂

Don’t succumb to NHH (not hosted here) when there’s a public service available that will do the job better.

Hell yes. Great advice in this piece.

Elsewhere…

There are lots of hosting comparisons out there, most coming from either a pro-Heroku or anti-Heroku bias. This recent article by Daniel Rice was more balanced and honest about the trade-offs between some popular options. He uses Rails as an example, but the products and tradeoffs are fair regardless of language or framework.

Speaking of hosting options, I recently learned about HatchBox, the latest entry in the developer-experience-of-heroku-but-cheaper pack (Rails only). Count me as skeptic, but I’m a fan of Chris Oliver’s previous work, so here’s how to migrate from Heroku if you want to give it a spin.

If you’ve eliminated every bottleneck in your app and want to eek out a bit more performance for users around the world, Vladimir Yartsev will show you how to use Cloudflare’s Railgun product to compress and speed up traffic between your CDN (Cloudflare) and your origin server (Heroku). Pretty cool, but let’s be real — you and I are far from ready for that level of optimization.

Can I link my own article from my own newsletter? Pretty sure I can! I assembled Six Tips for Mastering your Procfile because hey, we’ve all got one.

From the archives…

If you use Postgres, you want to listen to Craig Kerstiens. His articles Understanding Postgres Performance and More on Postgres Performance are ancient by web standards, but as relevant today as ever.

For many application developers their database is a black box. Data goes in, comes back out and in between there developers hope its a pretty short time span.

Craig doesn’t want you to be one of those developers, and neither do I. Bookmark those articles and revisit often.

Tips and tactics…

Let’s stick with Postgres for today’s tips. Much as I love my command line, when it comes to exploring my database, I like a GUI, and the GUI I like is pgweb. It’s open source, cross-platform, and it doesn’t try to do too much.

You launch pgweb via the command line, so connecting to your production database is this easy:

heroku config:get DATABASE_URL | xargs pgweb --url

While you’re in there, here’s a fun query that’ll show your current database connections, where they’re coming from, and what they’re executing:

SELECT * from pg_stat_activity
WHERE datname IS NOT NULL
AND pid <> pg_backend_pid()
ORDER BY application_name

Neat!

If you want to dig into your query performance, pg_stat_statements is your friend (thank Craig for this one):

SELECT 
  (total_time / 1000 / 60) as total_minutes, 
  (total_time/calls) as average_ms,
  calls,
  query 
FROM pg_stat_statements 
ORDER BY 1 DESC
LIMIT 100

Postgres is awesome! 😀

Parting question…

What dev-ops challenge did you face recently that took you longer than you felt it should? Reply and let me know.

Thanks for reading!
—Adam