← All workBalaji SankarCase study 07 / 12
D2C ecommerce / print-on-demand2026NDA · name withheld

Storybook PrintEngine

From checkout to printing press for a personalised book brand selling in two countries. I built the storefront and an automated 300 DPI print pipeline, then replaced hand-coded page layouts with a declarative book engine and a visual builder.

Case study by Balaji Sankar · Updated October 2026

Client

A personalised children’s book brand

Role

Lead full-stack engineer

Timeline

2026

Stack
Next.jsReact 19TypeScriptMongoDBPrismaBullMQRedis@react-pdf/rendererSharpExpressAWS EC2S3RazorpayStripe
Outcomes
<1s

Page preview render

<30s

Full page generation, including every character variant

✦

Generation time roughly halved versus the headless-Chrome renderer

✦

Launching a new book is now a configuration task, not an engineering project

01 / 09The opportunity

Why did it need to exist?

The issue
  • Every book layout was hand-coded
  • Headless Chrome screenshots were slow and fragile
  • Preview and printed book could disagree
  • A new title needed an engineer
The solution
  • A schema-driven book engine with layered pages
  • A separate render service with a job queue
  • One definition drives preview and print
  • Books defined as data, not code
02 / 09The challenge

What made it hard?

A parent picks a title, tells the site about their child, pays, and a printed book arrives. Behind that is a full business: two currencies, two payment providers, tax invoices, shipping rules and an order pipeline that has to end in a print-ready file with bleed and trim marks, every time, with no designer involved.

The first version worked, but every book was hand-coded and rendered by screenshotting pages in headless Chrome. Adding a title meant an engineer writing layout code, and the renderer was slow, memory-hungry and failed in ways that were hard to reproduce - nowhere near ready for the catalogue the business wanted.

03 / 09Approach

How did I approach it?

01

Commerce as data

One codebase serves both countries, with pricing, currency, shipping and tax handled as data, and signature-verified, idempotent webhooks for both payment providers so retried deliveries cannot duplicate an order and late failure events cannot un-pay a paid one.

02

Engine, not books

I replaced the headless-Chrome renderer with a schema-driven engine. Each book is one definition - variables, characters, customer questions and pages built from layers with structured visibility rules. The same definition drives the live browser preview and the server-side print render.

03

A builder for non-engineers

A visual admin tool with a canvas, layer inspector, rule editor, an asset matrix for character variants, localised text and validation. Launching a title became a configuration task.

04

Rendering as its own service

I split rendering into a standalone service with an authenticated API, a job queue, per-order signed requests and a sweeper that recovers stalled renders, so the storefront never shares memory with a heavy print job.

04 / 09Key decisions

Which calls shaped it?

(01)

An engine instead of hand-coded books

Problem

Each product's layout lived in code, so the catalogue could only grow as fast as engineers could write layouts.

Decision

I replaced the headless-Chrome renderer with a schema-driven engine where each book is one definition that drives both the preview and the print file.

Outcome
  • A new book is a configuration task
  • Preview and print come from one definition
  • About twice as fast as the old renderer
(02)

Split rendering into its own service

Problem

Large print jobs shared resources with the storefront and failed in hard-to-reproduce ways.

Decision

Rendering moved to a separate service with a BullMQ and Redis job queue, signed requests and a sweeper for stalled jobs.

Outcome
  • The storefront never shares memory with print jobs
  • Stalled renders recover automatically
  • Previews under a second, pages under 30 seconds
(03)

Idempotent payment webhooks

Problem

Two payment providers can retry or send late events, risking double-processed or wrongly updated orders.

Decision

Razorpay and Stripe webhooks are signature-verified and idempotent, so repeats and late events cannot change a settled order.

Outcome
  • No double-processed orders
  • Late events cannot undo a settled order
  • Safe retries from both providers
05 / 09What I built

What did I build?

Personalised-book commerce and print platform
Personalised-book commerce and print platform1 / 3
  • (01)

    Paid orders flow through a queue that renders every page at 300 DPI, assembles a press-ready PDF with bleed and trim marks, and stamps the order ID into the bleed.

  • (02)

    Preview and print resolved from one source of truth, removing a whole class of "preview doesn’t match the book" bugs.

  • (03)

    Print-grade details solved in code: clean font names for prepress tools, a patched font library for Indic and accented names, and deliberate RGB output after finding that naive CMYK conversion inverts colours in the printer’s software.

  • (04)

    Stable job ids so webhook retries collapse into a single render, while admin re-renders get their own.

  • (05)

    Legacy books migrated by a converter, and the old headless-Chrome path deleted outright.

06 / 09Foundation

What is it built on?

One source of truth

The same book definition drives what parents preview and what the press prints.

Markets are configuration

Country differences live in middleware, not duplicated code.

Print-grade by default

300 DPI, bleed and trim on every order, with no designer involved.

Storefront
Next.jsTypeScriptMarket middleware
Data and queues
MongoDBPrismaBullMQRedis
Render service
Express@react-pdf/rendererSharpSigned job requests
Payments
RazorpayStripeIdempotent webhooks
Infrastructure
AWS EC2AWS S3
07 / 09Delivery

How was it delivered?

  1. Phase 1

    Two-market storefront

    Cart and checkout for two countries, with each market handled by middleware.

  2. Phase 2

    Payments

    Razorpay and Stripe with signature-verified, idempotent webhooks.

  3. Phase 3

    Print pipeline

    Automated 300 DPI press-ready PDFs with bleed and trim.

  4. Phase 4

    Book engine

    A schema-driven definition for each book, driving both the browser preview and the print render.

  5. Phase 5

    Render service

    Rendering split into its own service with a job queue, signed requests and stalled-job recovery.

08 / 09Reflection

What did I learn?

01

Engines beat one-offs

Moving books into data turned engineering work into configuration for the business.

02

Isolate heavy work

A separate render service made failures recoverable and kept the storefront fast.

03

Test with the printer

Naive CMYK conversion without an ICC profile inverted colours in the printer's software, so output stayed deliberately RGB.

09 / 09FAQ

Questions about this project

What did Balaji Sankar build in the Storybook Print Engine project?
From checkout to printing press for a personalised book brand selling in two countries. I built the storefront and an automated 300 DPI print pipeline, then replaced hand-coded page layouts with a declarative book engine and a visual builder.
Who was the client?
A personalised children’s book brand, in D2C ecommerce / print-on-demand. The work is under NDA, so the client is not named.
What was the hardest part?
A parent picks a title, tells the site about their child, pays, and a printed book arrives. Behind that is a full business: two currencies, two payment providers, tax invoices, shipping rules and an order pipeline that has to end in a print-ready file with bleed and trim marks, every time, with no designer involved.
What was his role?
Lead full-stack engineer.
What technology was used?
Next.js, React 19, TypeScript, MongoDB, Prisma, BullMQ, Redis, @react-pdf/renderer, Sharp, Express, AWS EC2, S3, Razorpay and Stripe.
What were the results?
<1s page preview render, <30s full page generation, including every character variant, Generation time roughly halved versus the headless-Chrome renderer and Launching a new book is now a configuration task, not an engineering project.

Have a project like this?

Tell me what you’re building or what’s broken. I’ll tell you straight whether I’m the right person for it.

Next caseHospitality / venue booking2025-26Ubox→