Two AWS designs for an image pipeline
A comparison of a Node.js worker you run yourself and a setup with presigned uploads plus Lambda. What each design includes, and how to choose.
This post compares two AWS designs for the same job. A cook uploads a cover photo. Something stores the original. Something produces an 800 px derivative.
Sunday Pantry is a small recipe website that needs that outcome in every post in this series. The AWS pieces changed. One design is an app you run. The other lets AWS start the work after a browser PUT.
This post does not introduce a new service. It compares the two designs and when to use each one.
What the two designs are
App-owned worker. The API receives the file, writes S3, writes a DynamoDB row (stored), and sends an SQS message you defined. A Node process long-polls, claims the row, resizes, marks ready, deletes the message. A DLQ catches poison JSON.
Serverless path. The API creates a presigned PUT URL. The browser writes to an originals bucket. S3 notifies a queue. Lambda parses the nested S3 event, resizes, and writes a second bucket so notifications do not loop.
Both designs show up in production image pipelines, document converters, and other jobs that start when a file lands in S3.
App-owned: Client → API → S3 + DynamoDB + SQS → your worker → S3
Serverless: Client → API (URL only) → client PUT S3 → SQS → Lambda → S3 (other bucket)The first line is the Fastify (or Nest) story from the start of the series. The client sends the file to your API. Your API writes the original, records status, and enqueues work. Your worker does Sharp.
The second line is the later story. The API only returns a short-lived upload URL. The browser PUTs the file to S3. S3 tells SQS. Lambda does Sharp into a different bucket.
Same cover in. Same WebP out. Different who runs the poll loop, and different who sees the original bytes first.
What you run yourself
The app-owned path means you run a worker that must stay up. You choose machine size, deploy the worker next to the API or on its own box, and debug with a normal Node inspector.
You also keep a status row. The UI can show stored / working / ready without listing S3. Conditional updates stop two workers from doing the same Sharp work when SQS delivers twice.
The API sees the bytes. You can reject a 40 MP dump before it hits S3, or strip EXIF in the same request you still answer with 202 after PutObject. HTTP 202 means accepted for later work, not “the web cover is ready.”
Cost while idle: your worker still polls (WaitTimeSeconds: 20 keeps that cheap, not free if you run extra instances).
This design fits a team that already runs Node services. A second process is a known shape. You can attach a debugger. You can use a Dockerfile you already understand.
What AWS runs for you
The serverless path removes the poll loop. Idle traffic does not need a Node process waiting on SQS. Lambda scales with the queue.
The API stays small: filename in, URL out. Bandwidth for the original never hits your server. That matters on a tiny instance and on a cook with a 12 MB photo.
You give up an easy place to put “must inspect bytes before they exist in S3.” Scan and resize happen after the object is there (Lambda, or a second function). Status is often “object exists in originals” and “object exists in web,” unless you add DynamoDB in the handler.
You take on packaging (Sharp’s native binary), IAM for the function, visibility timeout vs Lambda timeout, and batch failure behavior. S3 notifications add a queue policy and key decoding.
IAM is the permission system. The function role must read the originals bucket and write the web bucket. The event source mapping must receive from the queue. Visibility timeout on the queue should be longer than the Lambda timeout, so a second invoke does not start while the first is still running. Two buckets stop a write from firing another notification.
Side-by-side comparison
Question | App-owned worker | Serverless path |
|---|---|---|
Who receives the original bytes first? | Your API | S3 (after a URL you signed) |
Who starts the resize? | Your | S3 event → SQS |
Who polls SQS? | Your | Lambda event source mapping |
Natural place for job status? | DynamoDB item | S3 keys, or a table you add |
Duplicate delivery? | SQS at-least-once; claim with DynamoDB | SQS + S3 at-least-once; idempotent output key |
Loop risk? | Low if the worker writes a prefix you do not enqueue | High if Lambda writes the watched bucket |
Fits a workshop / LocalStack replica? | Yes: API + worker processes | Yes: create URL, PUT, invoke handler |
These rows are constraints, not scores. Read them as “who owns this part,” not as a ranking.
Duplicate delivery means SQS can hand the same message out more than once. On the app-owned path, a DynamoDB claim stops two workers from both resizing. On the serverless path, write the same web key every time so a second run overwrites the first.
Loop risk means a processed write that triggers the same pipeline again. The serverless path watches an S3 bucket. If Lambda writes back into that bucket, S3 notifies the queue again.
When to use a Node.js worker
- You already run Node services and adding a second process is easy.
- The product needs explicit status and a claim so two consumers cannot both email “your cover is ready.”
- You must validate or transform bytes before they sit in a bucket other teams can read.
- You want a debugger on the worker and a Dockerfile you already understand.
- The team is learning SQS and DynamoDB on purpose. That path teaches queues, visibility, DLQs, and conditional writes in one story (store and 202, the queue, DLQs, the claim).
Choose this path when the API must see the file, or when the UI must show working versus ready. The status row is then a first-class part of the design, not an extra table you add later.
When to use Lambda
- You do not want a long-running consumer.
- Uploads are large or frequent enough that proxying through the API is the bottleneck.
- The next step after S3 is already event-driven (thumbnails, virus scan, metadata).
- A small Nest or Fastify app should only create upload URLs and not hold multipart buffers (presigned PUT, notifications, Lambda).
Choose this path when idle time should cost little, and when the original bytes do not need to transit your server. Lambda becomes the worker. You still need a DLQ, a second bucket, and a Sharp build that matches Amazon Linux.
You can mix. Some teams presign the upload, still write a DynamoDB row from a “complete” callback, and consume SQS with a worker they run. The posts split the shapes so each idea stayed in one article.
Common mistakes
Do not add Lambda because it is on a blog diagram. If one worker process handles the load, keep it.
Do not add DynamoDB because S3 exists. If the web key is a pure function of the original key and overwrites are fine, the table is optional.
Do not skip the DLQ on either path. Poison messages do not care which poller you use. A dead-letter queue is a second queue that holds messages that fail too many times.
Do not skip key decoding on the S3-event path. Object keys in notifications are URL-encoded. Decode before GetObject.
Do not skip HTTP 202 on the API-upload path. 202 means the original is stored and work will happen later. It does not mean the web cover is ready.
Do not run both pollers on the same queue. A Node while (true) loop and a Lambda event source mapping will fight over messages.
Do not write processed files to the watched bucket. Two buckets avoid the notification loop.
How to choose
Ask three questions:
- Must the API see the bytes? If yes, app-owned upload (or presign plus a mandatory scan bucket the client cannot read).
- Must we show
workingvsreadyin the UI? If yes, a table (or equivalent) plus a claim if you have more than one consumer. - Do we want to run a poll loop? If no, Lambda (or another managed consumer) on SQS.
Write the answers down. Then pick the shape. The services in this series match those answers: S3 for files, SQS for “do this later,” DynamoDB for “who owns this row,” and Lambda when you do not want to run a poll loop.
If you need to inspect the file before it sits in a bucket other people can read, start with the app-owned path. If the bottleneck is moving 12 MB through your API, start with the presigned path.
You can add a status table to Lambda later. You can add a presigned URL to an app that already has a worker. Start with the answers above so you do not build both by accident.
How to read this series
If you are learning AWS with Node.js, read them in order even if you already know which shape you want.
The first four posts are one path: accept the file, put a job on a queue, stop endless retries with a dead-letter queue, then claim the job in DynamoDB. That path matches a Fastify (or Nest) API plus a worker you start with tsx watch. You can point the SDK at a local emulator and see every call.
The next three posts are the other path: the API does not receive the file, S3 starts the job, Lambda is the worker. Same Sharp goal, different operations.
This comparison is last so you do not build both paths in one repo by accident: two queues, two buckets, and a worker that still polls while Lambda also consumes.
Pick one design. Build that one. Come back to the other when a real constraint forces the switch.
Further reading
Related posts
- Processing SQS messages with Lambda
How Lambda receives messages from SQS, parses the nested S3 event, resizes the image, and writes to another bucket. Also batches, timeouts, and Sharp on Amazon Linux.
- S3 event notifications to SQS
How an S3 ObjectCreated event can put a message on SQS. Covers the queue access policy, decoding object keys, and writing processed files to a different bucket.
- Presigned URLs for S3 uploads
How to generate a short-lived S3 PUT URL in Node.js so the browser uploads the file directly. Also CORS, matching signed headers, and why the URL is a secret.