Posts

Writing WebSocket Server Code With LLMs in November 2026: Authenticate the Upgrade, Check the Origin, and Plan for Dropped Connections

Image
Ask an LLM for "a WebSocket server for live notifications" and you will get something that works on your laptop in about thirty lines. It accepts a connection, broadcasts messages, and logs "client connected." Then it goes to production, and the problems show up: anyone can connect without logging in, a malicious page on another site can open a socket using your users' cookies, connections silently die behind a load balancer, one slow client eats memory, and every deploy disconnects everyone with no plan for reconnecting. None of these are exotic. They are the normal shape of long-lived connections, and generated code tends to skip them because the happy-path demo does not need them. This guide covers what to ask for, what to check in the output, and how to test it before real users rely on it. The examples use Node.js and the widely used ws library, but the same checklist applies to Python, Go, or any other stack. A WebSocket is a line that stays open in b...

Writing API Key Code for Your Own Service With LLMs in November 2026: Show the Key Once, Store Only a Hash, and Make Rotation Painless

Image
If your product has an API, sooner or later customers will ask for API keys so their scripts and servers can call it without a browser login. Ask an LLM to "add API key authentication" and you will usually get something that works on the first request: a random string, a column in the users table, and a middleware that compares the header to that column. It also tends to store keys in plain text, compare them in a way that leaks timing, give every key full access, and offer no way to rotate a key without breaking the customer's integration. This post walks through what a solid API key system for your own service looks like, how to prompt for it, and what to check in the code you get back. The examples use Python and PostgreSQL, but the ideas carry over to any stack. Anyone can cut a copy of a physical key. Make sure your API keys cannot be copied out of your database. Image: Key cutting machine by Fumikas Sagisavas, CC0 , via Wikimedia Commons. Decide what an API k...

Writing Rate Limiting Code for Your Own API With LLMs in November 2026: Key on the Right Identity, Keep Counters Where Every Instance Can See Them, and Return 429 With Retry-After

Image
Sooner or later every public endpoint needs a rate limit. A login form gets hammered by a password-guessing script, a single customer's runaway loop eats your database, or an expensive report endpoint gets called a thousand times a minute. Asking an LLM to "add rate limiting" is a reasonable first move, and it will produce something that looks finished in seconds. The trouble is that the most common generated version counts requests in a dictionary inside one process, keys on whatever IP header shows up first, and returns a bare error with no hint about when to come back. This post covers how to get an LLM to write server-side rate limiting that actually holds up: what to decide before you prompt, which generated patterns to reject, and how to test the limiter before real traffic does it for you. (If you are on the other side, calling someone else's rate-limited API, that is a different problem: back off and honor their Retry-After .) A turnstile lets people throu...

Writing CORS Configuration With LLMs in November 2026: List Exact Origins, Never Reflect the Origin With Credentials, and Test the Preflight With curl

Image
CORS errors are one of the most common reasons developers paste a stack trace into a chat window and ask an LLM to "just make it work." The model will happily oblige, and the fastest fix it knows is usually the worst one: allow every origin, reflect whatever the browser sends, and turn on credentials. The red error in the console goes away, and your API is now readable by any website a logged-in user happens to visit. This post walks through how to get an LLM to write CORS configuration that is actually correct: what to tell it up front, which patterns to reject on sight, and how to test the result from the command line before you deploy. Each stamp is an explicit, per-origin permission. Your CORS allowlist should work the same way. Image: Brazil, Iceland, UK, US passport stamps by Jon Evans, CC BY 2.0 , via Wikimedia Commons. What CORS actually does (and what it does not) Before prompting anything, it helps to have the model's job straight in your own head, beca...

Writing Search Endpoints With LLMs in November 2026: Use Your Database's Full-Text Search, Escape Every User Query, and Test Ranking With Real Searches

Image
Almost every app eventually grows a search box. Ask an LLM to "add search to the products page" and you will usually get something that works on the first try: a query with WHERE name ILIKE '%' || :q || '%' , wired to a text field. It returns results in the demo. Then the table grows, the query starts scanning every row, a user types 100% and gets everything, someone else searches for "running shoes" and finds nothing because the product is called "Shoes for running", and a customer sees a draft item that was never meant to be public. None of those problems are hard to avoid, but the model will not avoid them unless you ask. This post walks through how to get a search endpoint out of an LLM that is fast, safe with hostile input, respects permissions, and returns results people actually expect. The examples use PostgreSQL because it ships solid full-text search out of the box, but the same checklist applies to MySQL, SQLite FTS5, or a ded...

Writing Field-Level Encryption Code With LLMs in November 2026: Use an AEAD From a Vetted Library, Never Reuse a Nonce, and Plan Key Rotation on Day One

Image
Sooner or later a product stores something that should not sit in the database as plain text: a tax ID, a bank account number, an API token a customer handed you, a medical note. Disk encryption and TLS do not help much here, because anyone who can run a query, read a backup, or open a database dump still sees the value. Field-level encryption closes that gap by encrypting specific columns in your application before they ever reach the database. It is also a place where LLM-generated code goes wrong in quiet ways. The code runs, the round-trip test passes, and the flaw only matters when someone attacks it. This post covers how to ask a model for encryption code you can actually ship, what to check in what it gives you, and the tests that catch the common mistakes. Encryption is easy to get subtly wrong, which is why you should lean on vetted, well-studied designs. Image: Enigma rotor exploded view by Wapcaplet, CC BY-SA 3.0 , via Wikimedia Commons. Decide what you are protecting...

Writing Graceful Shutdown Code With LLMs in November 2026: Stop Taking New Work, Drain What Is In Flight, and Put a Deadline on All of It

Image
Every service gets stopped. Deploys, autoscaling, node maintenance, and crashes in a neighbor container all end the same way: the platform sends your process a signal and gives it a short window to exit. What happens in that window decides whether users see a clean handoff or a burst of 502s, half-written records, and jobs that silently vanish. Ask an LLM for "graceful shutdown" and you usually get something like process.on('SIGTERM', () => process.exit(0)) , or a handler that closes the database pool first and the HTTP server second. Both look tidy. Both drop work. This guide shows how to get shutdown code from an AI coding assistant that actually behaves: stop accepting new work, let in-flight work finish, close resources in the right order, and give up after a firm deadline. Flip the sign first, then serve the customers already inside. Image: Close-up of a closed sign hanging on a store door by Ivan Radic, CC BY 2.0 , via Wikimedia Commons. What actually ...