Engineering 2 min read

Small models belong at the edge

The author writes in one language. The model runs at publish time, the translation lands in D1, and the read path does not wait.

Small models belong at the edge

Most teams picture intelligence as a round trip: the request flies to a large model somewhere else, then flies back. A chat window can wait. A blog post and a publish button should not.

This site keeps the model on the write path. The author finishes in one language, hits publish, and the translation happens in that same action. The result is a row in D1. Later, a reader opens a finished page rather than a script that is still loading.

Why translate at publish time

Three concrete reasons:

  1. Cost stays predictable. The Workers AI free allotment resets daily. Translation happens when you publish, not on every read.

  2. The draft can be edited. The model hands you a draft. The title, the terms, and the sentence you share on X should be editable, and a language you have touched can be locked.

  3. Crawlers see a complete page. Search engines and answer engines read semantic HTML, including the summary and the FAQ, not an empty shell.

What belongs at the edge

Fits Does not fit
Translation, summaries, FAQ, labels Betting a whole conversation on the free allotment
One run at publish time Waiting on a large model inside every page request
A draft a person can revise Ephemeral generation with no record

Short code, links, and embed markers are not sent to the translator. This call stays as written:

const translated = await env.AI.run("@cf/meta/m2m100-1.2b", {
  text: paragraph,
  source_lang: "zh",
  target_lang: "ar",
});

The relationship with X

Technical discussion rarely lives in the comment box under a post. Each article keeps a share line, and the body can embed one public post.

When there is no embed, the page does not request a third-party script.

Arabic is not an extra language

Right-to-left is not finished when you set dir. Navigation, lists, and the quotation rule follow the inline direction, while code stays left to right. hreflang uses ar, and the sitemap and RSS each have an Arabic edition. Spanish joins the routes, the sitemap, and the switcher at /es/.

What to keep

  • One source language, and several published translations.
  • Model calls on the write path. The read path only touches the database and object storage.
  • A summary and a FAQ that a person can read, and a generative engine can read too.

Questions

Does the source language have to be Chinese?

Simplified Chinese is the default. The admin can choose any of the five languages as the source. The others are generated on publish.

What happens when the free allotment runs out?

The source is still saved. Automatic translation is marked pending. You can retry later or paste a translation yourself.

Will the next publish overwrite a translation?

A locked language is kept. An unlocked automatic draft is replaced only when you ask for a fresh translation.