All essays
Engineering

Behind the Scenes: How KDP Partner Generates a 25-Chapter Book in an Afternoon

The KDP Partner Team·Feb 5, 2026·12 min read

Anyone who has tried to generate a full book with an LLM knows the pain points: context runs out, chapters drift stylistically, one flaky API call kills the entire run at chapter 12.

Three ideas that hold it together

1) Rolling summaries: each chapter is summarized to ~200 tokens before the next is generated. The system prompt receives the last 3-5 rolling summaries, giving Claude enough continuity without paying for full context re-injection.

2) Checkpointed background jobs: every chapter is persisted the moment it's written. If the process restarts, an auto-resume worker looks at what's already in the DB and picks up from the exact next chapter — no re-generation, no lost work.

3) SSE streaming with heartbeat: chapters stream token-by-token so the UI feels alive, and a 25s heartbeat keeps the job document warm so a mid-flight run never gets falsely marked stale.

The result

A 25-chapter, 1,500-word-per-chapter book takes about 45–70 minutes end-to-end, tolerates transient LLM 429s with exponential backoff, and survives full container restarts without losing a single chapter. Users can walk away and come back to a first draft.