Concept · client and server
Many clients, one server.
Every website and app you use is split in two. The client is the thing in your hand that asks. The server is a computer somewhere else that answers. We’ll use an app you already know, the debate rebuttal app, and follow what happens in the seconds after you press Generate rebuttal.
That form is the client side. Everything that happens after you press the button is the subject of this page.
The two roles
They never share memory. The only thing that crosses between them is a message, an HTTP request, and the message that comes back, an HTTP response.
The picture
Why put a server in the middle?
- Shared data. Ana saves a practice on her laptop and it appears under Saved practices on Eli’s phone. Their devices never talk to each other; both talk to the server, and the server reads the same database.
- Secrets. Every rebuttal costs money at OpenAI. The key that pays for it lives on the server. Anything sent to a browser can be read by whoever holds the browser (right-click, View Source).
- Rules. The server decides what is allowed: no empty speeches, side must be pro or con. A client can be changed by anyone; the server is the owner’s.
- One place to update. Deploy a fix once and every client gets it on the next request.
The life of one request
Ana is on the con side. She pastes her constructive (“We negate. Contention 1: Affordability and competition…”), picks Con, and presses Generate rebuttal. Here is everything that happens, in order. Step through it.
You clicked Generate rebuttal. The browser knows the name debate-app.debate-app.workers.dev, but computers find each other by number (an IP address). It asks DNS, the internet’s phone book. (It already did this when the page first loaded, so this time the answer is remembered and the step is skipped.)
What the request actually looks like
HTTP is just text. This is step 4, roughly what leaves Ana’s browser when she presses the button. The three form fields travel in the body, exactly as they are named in the form:
POST /?/generate HTTP/1.1 Host: debate-app.debate-app.workers.dev Content-Type: application/x-www-form-urlencoded topic=Should+major+economies+prioritize+domestic+energy+independence… &side=con &draft=We+negate.+Contention+1%3A+Affordability+and+competition…
And step 10, the response that comes back:
HTTP/1.1 200 OK Content-Type: text/html …You argued con. The reply is pro. 720 words, about 3:36–4:14 at 170–200 words per minute. [the rebuttal speech, point by point, with why each one weakens your case]
POSTthe method: what kind of ask.GETreads (“show me the page”),POSTsends something new (“here is my speech”)./?/generatethe path: which thing on the server. The form saysaction="?/generate"; the delete button uses?/delete.- Headers: notes on the envelope, like which website this is for (
Host) and how the body is packed. - Body: the content itself:
topic,side,draft. 200the status code: 2xx worked, 4xx you asked wrong (an empty speech, a page that doesn’t exist: 404), 5xx the server broke (say, OpenAI was down).
The real app uses a little JavaScript, so the browser actually sends the same three fields packed slightly differently and gets the result back as data instead of a whole new page. The idea is identical: one request in, one response out. Open your browser’s developer tools (Network tab) on the debate app and press the button to watch it happen.
Every button is a request
Generating a rebuttal is the big one, but everything you do in the debate app is a request of its own. Notice which ones need OpenAI and which only need the database:
GET /serverdatabaseLoads the form, plus the Saved practices list read from the database.POST /?/generateserverOpenAIdatabaseThe walk-through above. Slow (seconds), costs money.GET /?task=ba60ccb1…serverdatabaseReads that practice back by its id. No OpenAI: the rebuttal was already written and saved, so it’s instant and free.POST /?/deleteserverdatabaseRemoves the row. It disappears from everyone’s list.The ?task=… in the address bar is the id the database gave the practice in step 9. Copy that link to a friend and their browser sends the same GET; the server looks up the same row; they see the same rebuttal.
The server’s side, in code
The debate app is built with SvelteKit, the same tool as this site. Its server side could look something like this sketch (not the app’s actual code, but the same shape). You won’t write this by hand: you’ll ask your agent for it. But now you can read what it wrote.
import OpenAI from 'openai';
import { fail } from '@sveltejs/kit';
// GET / and GET /?task=… : only the database
export async function load({ url, platform }) {
const db = platform.env.DB;
const tasks = await db.prepare('SELECT id, topic, student_side FROM tasks ORDER BY created_at DESC').all();
const id = url.searchParams.get('task');
const selected = id ? await db.prepare('SELECT * FROM tasks WHERE id = ?').bind(id).first() : null;
return { tasks: tasks.results, selected };
}
export const actions = {
// POST /?/generate
generate: async ({ request, platform }) => {
const form = await request.formData(); // 4 read the request
const topic = form.get('topic'), side = form.get('side'), draft = form.get('draft');
if (!topic || !draft || !['pro', 'con'].includes(side)) // 5 check the form
return fail(400, { error: 'Fill in every field.' });
const openai = new OpenAI({ apiKey: platform.env.OPENAI_API_KEY }); // key stays here
const ai = await openai.responses.create({ // 6–7 call the LLM
model: 'gpt-5-mini',
input: `Resolution: ${topic}\nThe student argued ${side}. Their constructive:\n${draft}\n\n` +
`Write the opposing rebuttal. Answer the claims they actually made.`,
});
const id = crypto.randomUUID();
await platform.env.DB // 8–9 save it
.prepare('INSERT INTO tasks (id, topic, student_side, draft, speech, created_at) VALUES (?, ?, ?, ?, ?, ?)')
.bind(id, topic, side, draft, ai.output_text, new Date().toISOString())
.run();
return { id, speech: ai.output_text }; // 10 the response
},
// POST /?/delete
delete: async ({ request, platform }) => {
const id = (await request.formData()).get('id');
await platform.env.DB.prepare('DELETE FROM tasks WHERE id = ?').bind(id).run();
},
};Many clients at once
While Ana waits for her rebuttal, Dee is generating one for the pro side, Eli is opening a saved practice on the bus, and a whole debate class may be pressing the button at once. The server handles each request on its own: it doesn’t remember Ana between requests, which is exactly why it can serve a whole class (or thousands of people). Everything that must be remembered goes into the database; the clever part, writing the speech, comes from OpenAI; the server is the traffic controller in the middle.