Short answer: for a B2B SaaS system that watermarks sensitive PDFs before emailing them to customers, keep the Node.js API out of the document hot path. Accept a job, render the customer-specific watermark, encrypt the finished PDF, store that immutable artifact, and only then enqueue email delivery. Use owner-password encryption to control changes, a distinct user password to open the file, and deliver that password through a separate authenticated channel. This adds queueing and storage, but it prevents slow PDF work from consuming request capacity and makes the ordering invariant enforceable: no plaintext artifact reaches the mailer.

PDF password protection is useful defense in depth, not a substitute for access control or transport security. A recipient who can open a document can still photograph it, copy permitted content, or disclose the password. The watermark provides attribution; encryption protects the file while it is stored or forwarded. Those are different jobs.

How should a PDF API approach password protection and encryption?

I use a bounded failure scenario when reviewing this design: a batch of 10,000 account statements becomes eligible at once, each requires a customer watermark, and mail delivery slows after document generation has started. This is a capacity-planning exercise, not a claim about a production incident. The useful question is what the system does when generation is faster than delivery and retries overlap.

The first draft often looks deceptively clean: an HTTP handler fetches a source document, watermarks it, encrypts it, attaches it, and waits for the mail provider. Under a batch spike, CPU-heavy PDF transforms occupy the same workers serving interactive traffic. If the request times out after the message is accepted, an uncoordinated retry may send a duplicate. If encryption fails after watermarking, a loosely designed pipeline may leave a plaintext intermediate where a mail worker can find it.

The invariant is stricter than "call encryption before send." A mail job must reference only an encrypted, content-addressed artifact whose metadata records the tenant, recipient, watermark policy, encryption-policy version, and source digest. Plaintext should exist only inside a bounded worker workspace, never in the mail queue or durable attachment store.

No exceptions.

This changes the SLO discussion. API acceptance latency, document completion latency, and mail-delivery latency are separate service indicators. A single end-to-end average hides queue saturation; the useful signals are p95 job age, oldest ready job, transform duration by input-size bucket, retry count, and terminal-failure rate. Set objectives from the business deadline, then derive worker capacity from measured service time rather than guessing a concurrency value.

The pipeline I would operate

The API validates authorization and a stable idempotency key, snapshots the document request, and returns a job identifier. A worker claims the job with a lease. It reads the source into ephemeral storage, applies the visible watermark, produces a new PDF, encrypts that final byte stream, verifies that the output is encrypted and parseable, uploads it under a new object key, and atomically marks the job ready. Only the ready transition emits the mail task.

Order matters. Encrypting before watermarking requires decrypting again to modify the pages, widening plaintext exposure and complicating key handling. Watermarking after email preparation risks attaching the wrong derivative. In-place overwrite is also a poor fit: retries cannot distinguish a complete artifact from a partial one, and forensic comparison becomes harder. Write a new object, verify it, then publish its identity.

That last step is the commit point.

Keep passwords out of job payloads, logs, traces, object metadata, and email bodies. Generate them with a cryptographically secure random source, store only what the chosen retrieval flow requires, and expose them through an authenticated portal or another channel whose compromise is not identical to mailbox compromise. Do not derive a password from an email address, customer ID, invoice number, or other guessable data.

The following Go sketch shows the preventative boundary. The concrete PDF engine sits behind an interface because encryption support, resource use, and validation behavior must be tested rather than inferred from a package name.

package documents import ( "context" "crypto/sha256" "errors" "fmt" ) type Engine interface { Watermark(ctx context.Context, source []byte, label string) ([]byte, error) Encrypt(ctx context.Context, source []byte, userPassword, ownerPassword []byte) ([]byte, error) VerifyEncrypted(ctx context.Context, source []byte) error } type Store interface { PutIfAbsent(ctx context.Context, key string, body []byte) error } func BuildArtifact(ctx context.Context, e Engine, s Store, source []byte, label string, userPassword, ownerPassword []byte) (string, error) { if len(userPassword) == 0 || len(ownerPassword) == 0 { return "", errors.New("both PDF passwords are required") } marked, err := e.Watermark(ctx, source, label) if err != nil { return "", fmt.Errorf("watermark: %w", err) } encrypted, err := e.Encrypt(ctx, marked, userPassword, ownerPassword) if err != nil { return "", fmt.Errorf("encrypt: %w", err) } if err := e.VerifyEncrypted(ctx, encrypted); err != nil { return "", fmt.Errorf("verify encrypted artifact: %w", err) } digest := sha256.Sum256(encrypted) key := fmt.Sprintf("protected/%x.pdf", digest) if err := s.PutIfAbsent(ctx, key, encrypted); err != nil { return "", fmt.Errorf("publish artifact: %w", err) } return key, nil } 

The mailer receives key, not bytes and not a mutable path. The state transition that publishes key must be conditional on the current job state, so two workers cannot both announce completion. Email sending needs its own idempotency record because exactly-once delivery is not a realistic assumption across a queue and an external mail system.

Throughput is a budget, not a concurrency knob

Start with arrival rate and measured service time. If the batch admits 10,000 documents over 20 minutes, the average arrival rate is about 8.3 jobs per second. If a representative transform consumes 750 milliseconds of worker CPU, the nominal requirement is 6.25 CPU-seconds per wall-clock second before headroom, retries, storage latency, and size skew. This is arithmetic on the stated scenario, not a benchmark. Real capacity must come from load tests using the actual page counts, fonts, images, watermark complexity, and encryption settings.

Now stress the assumption: if the large-document tail takes five times longer than the representative transform, six nominal cores do not make the deadline predictable, because the average conceals head-of-line blocking and the queue keeps aging while retries compete for the same workers. Measure at least one full batch with the observed size distribution, reserve capacity for retry traffic, and calculate drain time again after removing a worker, since maintenance and failures do not wait for a convenient batch. Then cap admissions at a rate the degraded pool can sustain or accept, explicitly, that the completion SLO will be missed. This is the point where a capacity plan becomes an operating policy rather than a spreadsheet result.

Bound every queue. Admission control is better than swapping an entire node because an unbounded backlog retained source buffers. Separate small and large documents if their service-time distributions differ sharply, and cap per-tenant concurrency so one export cannot consume the fleet. Autoscaling on CPU alone reacts late; queue age and estimated drain time say more about the customer deadline.

Use a retry budget. Transient object-store or queue failures can retry with exponential backoff and jitter; malformed PDFs, unsupported encryption inputs, and policy-validation failures should become terminal without repeated CPU spend. A dead-letter workflow must preserve identifiers and sanitized error classes, never document content or passwords.

Retries consume capacity too.

My release gate would include golden-file tests for watermark placement, attempts to open with the right and wrong passwords, structural parsing after encryption, cancellation during each stage, duplicate job delivery, and forced failure immediately before and after artifact publication. Load tests should report distributions, not a lone throughput number. Watch resident memory as closely as CPU: a worker that handles pages in memory can hit its limit well before all cores are busy.

Buy, build, or isolate the PDF engine?

The Node.js service boundary does not dictate where PDF manipulation runs. A native library in each application worker minimizes hops but expands crash and memory impact. A self-hosted document worker creates an operational service but contains resource use. A managed conversion API transfers engine maintenance while adding data residency, external dependency, and lock-in questions. None wins without the workload and compliance constraints.

Approach Throughput control On-call burden Sensitive-data boundary Lock-in pressure
In-process library Shares limits with the API unless isolated Library upgrades and process failures stay with the team Can remain inside the application environment Usually tied to library behavior and PDF feature coverage
Dedicated worker service Independent queues, limits, and scaling Team owns deployment, sandboxing, fonts, and patching Can remain in a controlled network and storage plane Protocol can stay generic, implementation can change
Managed document service Capacity is bounded by quotas and provider behavior Less engine maintenance; more dependency management Documents cross an additional processor boundary API semantics, egress, and migration shape matter

I would require the same acceptance suite at the interface and run it against any candidate. Procurement claims do not establish output correctness. For batch throughput, ask for concurrency and payload limits, throttling semantics, regional processing choices, deletion guarantees, retry behavior, and a way to validate encrypted output. For a built system, price the on-call load, security patching, font reproducibility, parser sandboxing, and capacity reserve, not merely compute.

The decision rule is plain: choose the smallest operational boundary that can meet the measured completion SLO while keeping plaintext inside the approved trust boundary. Revisit it when volume distribution or compliance requirements change.

Where this advice stops

Password-protected PDF delivery is the wrong primary control when recipients need revocable access, fine-grained audit trails, or immediate removal after a mistake. A portal that authenticates every download can enforce those properties more directly, although a downloaded file can still escape. Highly sensitive workflows may prohibit email attachments entirely.

The limitation is fundamental: this approach is unsuitable when the sender must revoke access after delivery, when the recipient cannot use password-protected PDFs, or when policy forbids distributing secrets through a second channel. In those cases, choose authenticated portal delivery; for collaborative review that requires continuing control, choose a controlled document workspace. Those alternatives add identity, availability, and support dependencies, so they are trade-offs rather than upgrades.

There is no recall button inside a PDF.

PDF permissions also should not be described as digital rights management. They express viewer restrictions, while the open password controls decryption; recipient software and human behavior remain outside the sender's control. Digital signatures solve another problem again: they help a recipient assess document origin and integrity, not confidentiality. Use signatures when authenticity is required, encryption when confidentiality in the file is required, and a watermark when recipient attribution matters.

The 2026 implementation choice is therefore less about finding an encryption call and more about preserving a verifiable state transition under load. Watermark, encrypt, verify, publish, then enqueue delivery. Measure queue age, isolate expensive work from Node.js request handling, and treat secrets as a separate distribution problem. That architecture remains testable even when the PDF engine or mail transport changes.

Sources