Files
skills/public/deployment-heroku-addons.html
zeekayandHanzo Dev 9e10c1c10e Each llms index points at the other two
hanzoskills.com/llms.txt now opens with the install line, the API
reference index and the company index, so an agent that lands on any
one of the three can find the rest.

robots.txt claimed 537 documents while llms.txt counts 920. The number
is gone from robots.txt; llms.txt derives it.

public/ is regenerated from scripts/site.py, which it had fallen
behind: the copy-prompt menu and agent bar were in the generator and
not in the committed pages. tests/site.mjs passes against the result.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-11 00:27:59 -07:00

624 lines
31 KiB
HTML

<!doctype html>
<html lang="en"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>deployment-heroku-addons</title>
<meta name="color-scheme" content="dark">
<style>
/* Committed to one visual world: a dark instrument panel. No light variant —
the dot field and the hairline rules only read on black, and a naive
inversion would wash both out. Every colour is painted explicitly so the page
never borrows a host background. */
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
:root{
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
--font-zen-pixel-square:'Zen Pixel Square',monospace;
--mono:var(--font-zen-mono);
--sans:var(--font-zen-sans);
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
--r:999px; --r-soft:14px;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
/* The dot field. A halftone made of one repeating radial-gradient, faded out
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
/* No overflow clip here: the dot field is inset to the box already, and a clip
would cut off the copy-prompt menu. */
.hero{position:relative;border-bottom:1px solid var(--line)}
.hero::before{content:"";position:absolute;inset:0;
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
background-size:7px 7px;
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
pointer-events:none}
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
nav{border-bottom:1px solid var(--line)}
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
justify-content:space-between;align-items:center;gap:1rem}
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
text-transform:uppercase;color:var(--ink);text-decoration:none;
display:inline-flex;align-items:center;gap:.6rem}
.brand i{font-style:normal;color:var(--faint)}
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
text-transform:uppercase;color:var(--soft);text-decoration:none}
nav a.up:hover{color:var(--ink)}
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
h1 em{font-style:normal;color:var(--faint)}
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
line-height:1.2;font-weight:400}
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
.btn.solid:hover{background:#d8d8d4}
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
/* Copy-prompt selector. Each row copies the prompt for its own target. */
.copy{position:relative;display:inline-flex}
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
padding:.4rem;display:flex;flex-direction:column;
box-shadow:0 12px 32px rgba(0,0,0,.75)}
.menu[hidden]{display:none}
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
white-space:nowrap}
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
.mi:hover .mark{color:var(--ink)}
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
letter-spacing:.1em;text-transform:uppercase}
/* Works-with bar: one scrolling row, name and mark per agent. */
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
display:flex;align-items:center}
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
-webkit-overflow-scrolling:touch;
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
.bar::-webkit-scrollbar{display:none}
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
text-decoration:none;background:var(--ground)}
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
.agent .mark{width:.95rem;height:.95rem}
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
p{margin:0 0 1rem;max-width:70ch}
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
li{margin:.22rem 0}
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
text-decoration-color:var(--line-hi)}
a:hover{text-decoration-color:var(--ink)}
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
display:block;overflow-x:auto}
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
.curl{display:block;background:var(--panel);border:1px solid var(--line);
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
white-space:pre;line-height:1.9}
.curl b{color:var(--ink);font-weight:400}
.curl i{font-style:normal;color:var(--faint)}
/* index */
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
#q:focus{outline:none;border-color:var(--soft)}
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
text-transform:uppercase;margin:0 0 2rem}
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
padding-bottom:.45rem}
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
border-radius:var(--r-soft);text-decoration:none}
.row:hover{background:#0a0a0a}
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
color:var(--faint);font-size:.85rem}
footer a{color:var(--soft)}
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
margin:0 0 2rem;font-size:.85rem}
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
border-bottom:1px solid var(--line);padding-bottom:.4rem}
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
.fmap a:hover{text-decoration:underline}
.fmap div{color:var(--faint);line-height:1.5}
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
@media (max-width:640px){
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
.btns{gap:.5rem}
.btn{padding:.75rem 1.15rem;font-size:.68rem}
.copy,.copy .btn{width:100%;justify-content:center}
.menu{left:0;right:0;min-width:0}
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
.strip b{border-right:0;padding-right:0}
.bar{width:100%}
}
</style>
<link rel="alternate" type="text/markdown" href="/deployment-heroku-addons.md">
<link rel="icon" href="/favicon.svg">
<link rel="canonical" href="https://hanzoskills.com/deployment-heroku-addons">
</head>
<!-- Reading this with a machine? Every page here is also plain markdown.
This one: https://hanzoskills.com/deployment-heroku-addons.md
Index: https://hanzoskills.com/llms.txt
Corpus: https://hanzoskills.com/all.md
Append .md to any path for the markdown twin. -->
<body>
<nav><div class="in">
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
<a class="up" href="/">All skills</a>
</div></nav>
<div class="wrap">
<h1>deployment-heroku-addons</h1><p class="lede">Adding databases (Postgres, MySQL, MongoDB) to Heroku apps</p><h1>Heroku Add-ons</h1>
<p><strong>Scope</strong>: Heroku add-on ecosystem, Postgres, Redis, monitoring, logging, email services <strong>Lines</strong>: ~310 <strong>Last Updated</strong>: 2025-10-18</p>
<h2>When to Use This Skill</h2>
<p>Activate this skill when:</p>
<ul><li>Adding databases (Postgres, MySQL, MongoDB) to Heroku apps</li><li>Setting up caching with Redis or Memcached</li><li>Implementing application monitoring and error tracking</li><li>Configuring log aggregation and analysis</li><li>Adding email delivery services (SendGrid, Mailgun)</li><li>Setting up scheduled jobs with Heroku Scheduler</li><li>Optimizing add-on costs and performance</li></ul>
<h2>Core Concepts</h2>
<h3>Add-on Architecture</h3>
<p><strong>Provisioning</strong>: Add-ons as managed services</p>
<ul><li>Single command installation: <code>heroku addons:create</code></li><li>Automatic configuration injection (environment variables)</li><li>Independent lifecycle from app code</li><li>Shared or dedicated resources (plan-dependent)</li></ul>
<p><strong>Connection Pattern</strong>:</p>
<pre><code class="lang-bash"># Add-on creates config var automatically
heroku addons:create heroku-postgresql:essential-0
# Check created config vars
heroku config | grep DATABASE_URL
# DATABASE_URL: postgres://user:pass@host:5432/dbname</code></pre>
<p><strong>Pricing Tiers</strong>:</p>
<ul><li>Free/Hobby: Development and testing</li><li>Essential: Small production apps</li><li>Premium/Standard: Production-grade with SLA</li><li>Enterprise: High availability, dedicated resources</li></ul>
<h3>Add-on Categories</h3>
<p><strong>Data Stores</strong>:</p>
<ul><li>Heroku Postgres: Primary relational database</li><li>Heroku Redis: Caching, sessions, queues</li><li>MongoDB Atlas: Document database</li><li>Apache Kafka: Event streaming</li></ul>
<p><strong>Developer Tools</strong>:</p>
<ul><li>Heroku Scheduler: Cron-like job runner</li><li>Heroku Exec: SSH into running dynos</li><li>Heroku Connect: Salesforce data sync</li></ul>
<p><strong>Monitoring &amp; Logging</strong>:</p>
<ul><li>Papertrail: Log aggregation and search</li><li>New Relic: APM and performance monitoring</li><li>Sentry: Error tracking and debugging</li><li>LogDNA: Advanced log analysis</li></ul>
<p><strong>Performance</strong>:</p>
<ul><li>Fastly: CDN and edge caching</li><li>Cloudflare: DDoS protection and CDN</li><li>Advanced Scheduler: High-frequency cron jobs</li></ul>
<p><strong>Communication</strong>:</p>
<ul><li>SendGrid: Transactional email</li><li>Mailgun: Email API and SMTP</li><li>Twilio: SMS and voice</li></ul>
<hr>
<h2>Patterns</h2>
<h3>Pattern 1: Heroku Postgres Setup</h3>
<p><strong>Provision database</strong>:</p>
<pre><code class="lang-bash"># Essential plan (~$5/mo, 10GB storage, 20 connections)
heroku addons:create heroku-postgresql:essential-0
# Check status
heroku pg:info
# Output:
# Plan: Essential 0
# Status: Available
# Connections: 0/20
# PG Version: 15.3
# Created: 2025-10-18
# Data Size: 8.2 MB</code></pre>
<p><strong>Connection pooling</strong> (recommended for &gt;20 connections):</p>
<pre><code class="lang-bash"># Enable connection pooling (increases connection limit)
heroku pg:connection-pooling:attach DATABASE --as DATABASE_CONNECTION_POOL
# Use pooled connection
heroku config:set DATABASE_URL=$(heroku config:get DATABASE_CONNECTION_POOL_URL)</code></pre>
<p><strong>Python connection</strong> (using psycopg2):</p>
<pre><code class="lang-python">import os
import psycopg2
from urllib.parse import urlparse
DATABASE_URL = os.environ[&#x27;DATABASE_URL&#x27;]
# Parse connection URL
url = urlparse(DATABASE_URL)
conn = psycopg2.connect(
database=url.path[1:], # Remove leading &#x27;/&#x27;
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# Or use Django DATABASE setting
DATABASES = {
&#x27;default&#x27;: {
&#x27;ENGINE&#x27;: &#x27;django.db.backends.postgresql&#x27;,
&#x27;NAME&#x27;: url.path[1:],
&#x27;USER&#x27;: url.username,
&#x27;PASSWORD&#x27;: url.password,
&#x27;HOST&#x27;: url.hostname,
&#x27;PORT&#x27;: url.port,
}
}</code></pre>
<p><strong>Backup and restore</strong>:</p>
<pre><code class="lang-bash"># Create manual backup
heroku pg:backups:capture --app myapp
# List backups
heroku pg:backups
# Restore from backup
heroku pg:backups:restore b101 DATABASE_URL --app myapp
# Download backup
heroku pg:backups:download
# Schedule automatic backups (Premium plans only)
heroku pg:backups:schedule DATABASE_URL --at &#x27;02:00 America/Los_Angeles&#x27;</code></pre>
<h3>Pattern 2: Heroku Redis for Caching</h3>
<p><strong>Provision Redis</strong>:</p>
<pre><code class="lang-bash"># Mini plan (~$3/mo, 25MB memory)
heroku addons:create heroku-redis:mini
# Check status
heroku redis:info
# Output:
# Plan: Mini
# Status: available
# Version: 7.0.8
# Max Memory: 25 MB</code></pre>
<p><strong>Python (Django cache)</strong>:</p>
<pre><code class="lang-python"># settings.py
import os
CACHES = {
&#x27;default&#x27;: {
&#x27;BACKEND&#x27;: &#x27;django_redis.cache.RedisCache&#x27;,
&#x27;LOCATION&#x27;: os.environ.get(&#x27;REDIS_URL&#x27;),
&#x27;OPTIONS&#x27;: {
&#x27;CLIENT_CLASS&#x27;: &#x27;django_redis.client.DefaultClient&#x27;,
&#x27;SOCKET_CONNECT_TIMEOUT&#x27;: 5,
&#x27;SOCKET_TIMEOUT&#x27;: 5,
&#x27;CONNECTION_POOL_KWARGS&#x27;: {&#x27;max_connections&#x27;: 50}
}
}
}
# Use cache
from django.core.cache import cache
cache.set(&#x27;key&#x27;, &#x27;value&#x27;, 300) # 5 minutes
value = cache.get(&#x27;key&#x27;)</code></pre>
<p><strong>Node.js (with ioredis)</strong>:</p>
<pre><code class="lang-javascript">const Redis = require(&#x27;ioredis&#x27;);
const redis = new Redis(process.env.REDIS_URL);
// Set with expiration
await redis.set(&#x27;user:123&#x27;, JSON.stringify(userData), &#x27;EX&#x27;, 3600);
// Get
const data = await redis.get(&#x27;user:123&#x27;);
const user = JSON.parse(data);
// Pub/Sub pattern
const subscriber = new Redis(process.env.REDIS_URL);
subscriber.subscribe(&#x27;notifications&#x27;);
subscriber.on(&#x27;message&#x27;, (channel, message) =&gt; {
console.log(`Received ${message} from ${channel}`);
});
// Publish
await redis.publish(&#x27;notifications&#x27;, &#x27;New order received&#x27;);</code></pre>
<p><strong>Session storage</strong>:</p>
<pre><code class="lang-python"># Django sessions in Redis
SESSION_ENGINE = &#x27;django.contrib.sessions.backends.cache&#x27;
SESSION_CACHE_ALIAS = &#x27;default&#x27;</code></pre>
<h3>Pattern 3: Papertrail for Log Management</h3>
<p><strong>Provision Papertrail</strong>:</p>
<pre><code class="lang-bash"># Choklad plan (free, 50MB/mo, 2-day retention)
heroku addons:create papertrail:choklad
# Open dashboard
heroku addons:open papertrail</code></pre>
<p><strong>Search logs via CLI</strong>:</p>
<pre><code class="lang-bash"># Search for errors
heroku logs --tail | grep ERROR
# Or via Papertrail CLI
papertrail -f -S &#x27;error OR exception&#x27;
# Search specific time range
papertrail -S &#x27;status=500&#x27; --min-time &#x27;1 hour ago&#x27;</code></pre>
<p><strong>Structured logging</strong> (Python):</p>
<pre><code class="lang-python">import logging
import json
# JSON formatter for better Papertrail parsing
class JSONFormatter(logging.Formatter):
def format(self, record):
log_data = {
&#x27;timestamp&#x27;: self.formatTime(record),
&#x27;level&#x27;: record.levelname,
&#x27;message&#x27;: record.getMessage(),
&#x27;module&#x27;: record.module,
}
if record.exc_info:
log_data[&#x27;exception&#x27;] = self.formatException(record.exc_info)
return json.dumps(log_data)
handler = logging.StreamHandler()
handler.setFormatter(JSONFormatter())
logger = logging.getLogger(&#x27;myapp&#x27;)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
# Use logger
logger.info(&#x27;User logged in&#x27;, extra={&#x27;user_id&#x27;: 123, &#x27;ip&#x27;: &#x27;1.2.3.4&#x27;})</code></pre>
<p><strong>Alerts</strong> (via Papertrail dashboard):</p>
<ul><li>Create search: <code>status=500</code></li><li>Set frequency threshold: <code>10 matches in 5 minutes</code></li><li>Send to: Email, Slack, PagerDuty</li></ul>
<h3>Pattern 4: SendGrid for Email</h3>
<p><strong>Provision SendGrid</strong>:</p>
<pre><code class="lang-bash"># Starter plan (free, 100 emails/day)
heroku addons:create sendgrid:starter
# Get API key
heroku config:get SENDGRID_API_KEY</code></pre>
<p><strong>Python (Flask-Mail)</strong>:</p>
<pre><code class="lang-python">from flask import Flask
from flask_mail import Mail, Message
import os
app = Flask(__name__)
app.config[&#x27;MAIL_SERVER&#x27;] = &#x27;smtp.sendgrid.net&#x27;
app.config[&#x27;MAIL_PORT&#x27;] = 587
app.config[&#x27;MAIL_USE_TLS&#x27;] = True
app.config[&#x27;MAIL_USERNAME&#x27;] = &#x27;apikey&#x27;
app.config[&#x27;MAIL_PASSWORD&#x27;] = os.environ.get(&#x27;SENDGRID_API_KEY&#x27;)
app.config[&#x27;MAIL_DEFAULT_SENDER&#x27;] = &#x27;[email protected]&#x27;
mail = Mail(app)
def send_welcome_email(user_email):
msg = Message(
subject=&#x27;Welcome to MyApp&#x27;,
recipients=[user_email],
body=&#x27;Thanks for signing up!&#x27;,
html=&#x27;&lt;h1&gt;Thanks for signing up!&lt;/h1&gt;&#x27;
)
mail.send(msg)</code></pre>
<p><strong>Node.js (SendGrid SDK)</strong>:</p>
<pre><code class="lang-javascript">const sgMail = require(&#x27;@sendgrid/mail&#x27;);
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
async function sendWelcomeEmail(email) {
const msg = {
to: email,
from: &#x27;[email protected]&#x27;,
subject: &#x27;Welcome to MyApp&#x27;,
text: &#x27;Thanks for signing up!&#x27;,
html: &#x27;&lt;h1&gt;Thanks for signing up!&lt;/h1&gt;&#x27;,
};
await sgMail.send(msg);
}</code></pre>
<h3>Pattern 5: Heroku Scheduler for Cron Jobs</h3>
<p><strong>Provision Scheduler</strong>:</p>
<pre><code class="lang-bash"># Free add-on
heroku addons:create scheduler:standard
# Open dashboard to configure jobs
heroku addons:open scheduler</code></pre>
<p><strong>Configure job</strong> (via dashboard):</p>
<ul><li>Frequency: <code>Every 10 minutes</code>, <code>Hourly</code>, <code>Daily</code></li><li>Command: <code>python manage.py cleanup_expired_sessions</code></li><li>Dyno size: <code>Standard-1X</code></li></ul>
<p><strong>Example commands</strong>:</p>
<pre><code class="lang-bash"># Data cleanup
python manage.py cleanup_old_records
# Report generation
python manage.py generate_daily_report &amp;&amp; python manage.py email_report
# Cache warming
python manage.py warm_cache
# Database maintenance
python manage.py vacuum_db</code></pre>
<p><strong>Alternative: APScheduler</strong> (in-process, for Standard+ dynos):</p>
<pre><code class="lang-python">from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler()
@scheduler.scheduled_job(&#x27;cron&#x27;, hour=2, minute=0)
def cleanup_task():
# Run at 2:00 AM daily
cleanup_old_records()
@scheduler.scheduled_job(&#x27;interval&#x27;, minutes=10)
def sync_task():
# Run every 10 minutes
sync_external_data()
scheduler.start()</code></pre>
<h3>Pattern 6: New Relic APM for Performance Monitoring</h3>
<p><strong>Provision New Relic</strong>:</p>
<pre><code class="lang-bash"># Wayne plan (free, 100GB/mo data)
heroku addons:create newrelic:wayne
# Open dashboard
heroku addons:open newrelic</code></pre>
<p><strong>Python (Django) integration</strong>:</p>
<pre><code class="lang-bash"># Install agent
pip install newrelic
# Generate config
newrelic-admin generate-config $NEW_RELIC_LICENSE_KEY newrelic.ini
# Update Procfile
web: newrelic-admin run-program gunicorn myapp.wsgi</code></pre>
<p><strong>Environment configuration</strong>:</p>
<pre><code class="lang-bash">heroku config:set NEW_RELIC_APP_NAME=&#x27;MyApp Production&#x27;
heroku config:set NEW_RELIC_LOG=stdout
heroku config:set NEW_RELIC_LOG_LEVEL=info</code></pre>
<p><strong>Custom instrumentation</strong>:</p>
<pre><code class="lang-python">import newrelic.agent
@newrelic.agent.function_trace()
def expensive_operation():
# Track function execution time
pass
# Record custom metric
newrelic.agent.record_custom_metric(&#x27;Custom/ActiveUsers&#x27;, user_count)
# Add custom attributes to transaction
newrelic.agent.add_custom_attribute(&#x27;user_id&#x27;, user.id)</code></pre>
<h3>Pattern 7: Cost Optimization Strategies</h3>
<p><strong>Review add-on costs</strong>:</p>
<pre><code class="lang-bash"># List all add-ons with pricing
heroku addons --all
# Check specific add-on details
heroku addons:info heroku-postgresql-12345</code></pre>
<p><strong>Optimization tactics</strong>:</p>
<p><strong>1. Right-size database</strong>:</p>
<pre><code class="lang-bash"># Downgrade if under-utilized
heroku pg:info # Check data size and connections
# If using &lt;3GB on Standard-0 (50GB, $50/mo)
# Downgrade to Essential-0 (10GB, $5/mo)
heroku addons:upgrade heroku-postgresql-12345 essential-0</code></pre>
<p><strong>2. Use connection pooling</strong> (instead of higher plans):</p>
<pre><code class="lang-bash"># Increases effective connection limit
heroku pg:connection-pooling:attach DATABASE</code></pre>
<p><strong>3. Consolidate Redis instances</strong>:</p>
<pre><code class="lang-bash"># Use namespaces instead of multiple Redis instances
# cache:user:123
# session:abc456
# queue:high_priority</code></pre>
<p><strong>4. Scale dynos during low traffic</strong>:</p>
<pre><code class="lang-bash"># Use Heroku Scheduler to scale down at night
# Job at 11pm: heroku ps:scale web=1 worker=0
# Job at 6am: heroku ps:scale web=2 worker=1</code></pre>
<p><strong>5. Remove unused add-ons</strong>:</p>
<pre><code class="lang-bash"># Destroy add-on (DESTRUCTIVE, backs up data first!)
heroku addons:destroy heroku-postgresql-12345 --confirm myapp</code></pre>
<hr>
<h2>Quick Reference</h2>
<h3>Common Add-ons</h3>
<pre><code>Add-on | Purpose | Free Tier | Paid From
---------------------|----------------------|------------------|------------
heroku-postgresql | Postgres database | No | $5/mo
heroku-redis | Redis cache | No | $3/mo
papertrail | Log management | 50MB/mo | $7/mo
sendgrid | Email delivery | 100/day | $15/mo
heroku-scheduler | Cron jobs | Yes (Free) | Free
newrelic | APM monitoring | 100GB/mo | $99/mo
sentry | Error tracking | 5K events/mo | $26/mo
cloudflare | CDN + DDoS | Yes | $20/mo
mailgun | Email API | 5K emails/mo | $35/mo</code></pre>
<h3>Essential Commands</h3>
<pre><code>Command | Purpose
------------------------------------------|----------------------------------------
heroku addons | List all add-ons for app
heroku addons:create addon:plan | Provision add-on
heroku addons:upgrade addon plan | Change plan
heroku addons:destroy addon | Remove add-on (destructive)
heroku addons:info addon | Show add-on details
heroku addons:open addon | Open add-on dashboard
heroku pg:info | Postgres database info
heroku pg:psql | Connect to Postgres CLI
heroku pg:backups:capture | Create database backup
heroku redis:info | Redis instance info
heroku redis:cli | Connect to Redis CLI</code></pre>
<h3>Configuration Best Practices</h3>
<pre><code>✅ DO: Use connection pooling for Postgres (increases connection limit)
✅ DO: Enable automatic backups for production databases
✅ DO: Monitor add-on metrics (CPU, memory, connections)
✅ DO: Use structured logging for better Papertrail searches
✅ DO: Set up alerts for critical errors (500s, exceptions)
✅ DO: Review add-on costs monthly and optimize
✅ DO: Use appropriate plan for workload (don&#x27;t over-provision)
❌ DON&#x27;T: Use Hobby tier for production (no SLA, limited resources)
❌ DON&#x27;T: Ignore connection pool exhaustion errors
❌ DON&#x27;T: Skip backups (data loss risk)
❌ DON&#x27;T: Provision multiple add-ons when one suffices
❌ DON&#x27;T: Hardcode add-on credentials (use environment variables)
❌ DON&#x27;T: Leave unused add-ons running (ongoing costs)</code></pre>
<hr>
<h2>Anti-Patterns</h2>
<p>❌ <strong>Using Hobby Postgres in production</strong>: No backups, limited connections, no SLA ✅ Use Essential tier minimum ($5/mo) with automatic backups enabled</p>
<p>❌ <strong>Not using connection pooling</strong>: Exhausts database connections quickly ✅ Enable <code>heroku pg:connection-pooling:attach</code> for apps with &gt;10 dynos</p>
<p>❌ <strong>Ignoring database connection leaks</strong>: Unclosed connections accumulate ✅ Use connection context managers (<code>with</code> in Python) and properly close connections</p>
<p>❌ <strong>Over-provisioning add-ons</strong>: Paying for unused capacity ✅ Monitor usage metrics and right-size plans (downgrade if under-utilized)</p>
<p>❌ <strong>Multiple Redis instances for same app</strong>: Unnecessary cost ✅ Use single Redis with namespaced keys (<code>cache:</code>, <code>session:</code>, <code>queue:</code>)</p>
<p>❌ <strong>Not monitoring add-on health</strong>: Silent degradation ✅ Set up New Relic/Papertrail alerts for errors, slow queries, high memory</p>
<p>❌ <strong>Skipping database backups</strong>: Risk of data loss ✅ Enable automatic backups and test restore process</p>
<p>❌ <strong>Hardcoding add-on URLs</strong>: Breaks on credential rotation ✅ Always use environment variables (<code>DATABASE_URL</code>, <code>REDIS_URL</code>)</p>
<p>❌ <strong>No error tracking in production</strong>: Blind to user-facing bugs ✅ Add Sentry or similar for exception monitoring</p>
<p>❌ <strong>Using free email tier for production</strong>: Rate limits, deliverability issues ✅ Upgrade to paid SendGrid/Mailgun plan with dedicated IP</p>
<hr>
<h2>Related Skills</h2>
<ul><li><code>heroku-deployment.md</code> - Deploying apps that use add-ons</li><li><code>heroku-troubleshooting.md</code> - Debugging add-on connection and performance issues</li><li><code>postgres-query-optimization.md</code> - Optimizing database queries for better performance</li><li><code>redis-caching-strategies.md</code> - Advanced Redis patterns for caching and queues</li><li><code>structured-logging.md</code> - Best practices for log formatting and analysis</li><li><code>cost-optimization-cloud.md</code> - General cloud cost management strategies</li></ul>
<hr>
<p><strong>Last Updated</strong>: 2025-10-18 <strong>Format Version</strong>: 1.0 (Atomic)</p>
<footer>
<div class="fmap">
<div><b>Build</b>
<a href="https://hanzo.app">hanzo.app</a> app builder
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
<div><b>Run</b>
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
<div><b>Account</b>
<a href="https://hanzo.id">hanzo.id</a> sign in
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
<div><b>Company</b>
<a href="https://hanzo.ai">hanzo.ai</a> canonical
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
</div>
<div class="fend"><a href="/deployment-heroku-addons.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
</footer>
</div></body></html>