Configuration Defaults: Decide Who Knows Enough to Choose

You are adding a receipt preview to an expense form. The layout gives you the target size, and the product requirement is clear: the preview must preserve the whole receipt, including the total at the bottom.

Then you open the thumbnail API. Before it will accept an image, it asks you for a buffer size, row batch size, worker count, retry count, and timeout. There is no option saying whether it may crop the receipt.

This is a hypothetical integration, but it makes the design problem visible. The calling feature has been given choices it cannot justify and has no way to express a choice it understands well.

Adding configuration can feel like making a module flexible. Each new option also assigns somebody a decision. When a receipt screen has to guess how a decoder should allocate memory, the API has moved unfinished implementation work into product code. Hiding whether the image will be cropped moves the decision in the other direction, away from the code that knows what the user needs.

We will review this TypeScript thumbnail contract one option at a time, separate request intent from processing policy, and give deployment constraints their own entry point. The result is a way to decide which controls to expose, which defaults to maintain, and what responsibility comes with removing a knob.

On this page

A Parameter Can Delegate an Unfinished Decision

Here is the request that leaves the receipt feature guessing:

type ThumbnailJob = {
  source: Uint8Array
  width: number
  height: number
  bufferBytes: number
  batchRows: number
  workerCount: number
  retryCount: number
  timeout: number
}

A caller cannot submit a job until it has values for every field. This creates an appearance of flexibility, but each parameter needs a reason and a contract.

The receipt engineer can obtain target dimensions from the layout requirement. They may know how long the interaction can reasonably wait. Neither fact explains a good row batch size for the decoder.

They may copy values from another caller, turning one unexplained choice into a convention. If that convention becomes inappropriate for larger images or a different execution environment, every copied setting becomes another place to inspect.

The task is not to remove configuration indiscriminately. It is to identify which decisions require caller knowledge and which ones are being exported because the implementation has not settled them.

Review the Knowledge Behind Each Choice

For this example, the review can start with a small ownership table:

ChoiceRelevant knowledgeLikely owner
Output width and heightRequired presentation dimensionsCalling feature
Cropping versus preserving contentWhether losing image content is acceptableCalling feature
Request budgetInteraction or background-job deadlineCalling feature
Buffer allocation and row batchingDecoder and transform implementationProcessor
Concurrent-job limitShared execution capacity and other workloadsProcessor policy, with trusted deployment input
Decoded-image limitSupported workload and resource budgetProcessor policy, with trusted deployment input
Retry behaviorWhether repeating the operation can help and is safeOperation contract, not an unexplained integer

The last three rows show why a simple “internal versus external” classification is insufficient. Some decisions belong in the service's policy but can legitimately vary by deployment. That does not mean every ordinary request should carry them.

The missing cropping choice now has a clear owner. The receipt feature knows that losing the bottom of the image could hide the total. The decoder knows how to fit pixels into a canvas. An API can expose plenty of machinery while leaving that important conversation impossible.

Express Intent at the Request Boundary

Give the feature a way to request the output it needs:

type ThumbnailRequest = {
  source: Uint8Array
  widthPx: number
  heightPx: number
  fit: 'contain' | 'cover'
  budgetMs: number
  signal?: AbortSignal
}

type Thumbnail = {
  bytes: Uint8Array
  widthPx: number
  heightPx: number
  format: 'png'
}

type ThumbnailService = {
  create(request: ThumbnailRequest): Promise<Thumbnail>
}

These are API sketches. They do not implement a decoder, image transformation, worker pool, or cancellation mechanism.

The units are explicit. Width and height describe output pixels rather than CSS dimensions. The request budget is a duration in milliseconds rather than an ambiguous timestamp. A real implementation must validate integer dimensions, supported limits, and a positive finite budget at runtime.

The fitting contract also needs to be stated. For this example, both modes produce the requested canvas dimensions and preserve the source aspect ratio. contain pads unused space with transparent pixels; cover fills the canvas by cropping excess image content. Output is PNG, so this operation does not ask callers to choose a format or a lossy-quality setting.

These are deliberately limited semantics. A receipt preview may require contain because cutting off a total is unacceptable. A decorative thumbnail may permit cover. The processor cannot discover that distinction from the source bytes alone.

An illustrative call might be:

declare const thumbnails: ThumbnailService

async function createReceiptPreview(
  source: Uint8Array,
  signal: AbortSignal,
): Promise<Thumbnail> {
  return thumbnails.create({
    source,
    widthPx: 320,
    heightPx: 200,
    fit: 'contain',
    budgetMs: 1500,
    signal,
  })
}

The dimensions and budget are example product inputs, not benchmark recommendations. Their suitability depends on the actual display and interaction requirements. What matters is that the caller can explain them using knowledge it already owns.

Defaults Need a Contract and an Owner

The receipt call is now easier to write, but the buffer and batching decisions have not vanished. Removing bufferBytes and batchRows means the processor has accepted responsibility for choosing them. Its maintainers still need an implementation policy, tests, supported workload limits, and a way to investigate bad behavior.

A default is not justified merely because a maintainer picked a round number. Its rationale might involve a decoder requirement, an established resource boundary, or measurements across the supported image sizes and formats. That evidence belongs with the processor's maintenance work.

Defaults also evolve. If batching changes, ordinary callers should not need new edits unless the public contract changes. Service maintainers should check the impact on latency, memory use, and cancellation responsiveness before releasing the new policy.

Some choices can adapt to observed conditions. A transport mechanism, for example, can estimate retry timing from observed responses. Evaluate whether the implementation can make a better-informed choice than its callers. Adaptation is useful only when the signal is relevant and the behavior remains within the operation's resource and correctness limits.

For this thumbnail service, an adaptive batching policy would need bounds. Measuring throughput does not justify ignoring a deadline or consuming all available memory.

Give Exceptional Knowledge a Focused Entry Point

There is a legitimate objection to hiding every processing control: an application may run this service in a constrained environment that the processor cannot fully observe. A trusted application bootstrap knows which other workloads share the runtime. Give that knowledge a deployment-level entry point:

type RuntimeLimits = {
  maxConcurrentJobs?: number
  maxDecodedPixels?: number
}

declare function createThumbnailService(
  limits?: RuntimeLimits,
): ThumbnailService

const constrainedThumbnails = createThumbnailService({
  maxConcurrentJobs: 1,
})

The service uses its documented default limits when overrides are absent. The example's limit of one concurrent job illustrates a deliberate capacity restriction; it is not an optimal value for all deployments.

This entry point is separate from the ordinary operation. A receipt component should not decide how much capacity remains for the entire application. Untrusted request input should not be allowed to loosen service resource limits.

Override semantics still need documentation and validation. Does the count limit active jobs or also queued work? Is the decoded-pixel limit per input or per operation? Does the implementation allocate additional working memory? A pixel cap alone is not a complete process-memory guarantee.

An override earns its place when the caller has specific relevant knowledge and can verify the effect. Exposing an internal tuning field “just in case” recreates the original uncertainty under a different name.

Failure and Cancellation Are Part of the Service

Pulling processing mechanics downward also creates obligations around failure. The service should not make each feature reconstruct which stage failed or remember to release an internal worker handle.

Its documented outcomes should distinguish invalid input, unsupported or malformed image data, exhausted budgets, cancellation, and processing failures at whatever level consumers genuinely need. Callers can then decide how to present or recover from the failed operation.

For the proposed contract, the budget covers queueing and processing from service acceptance. Expiry should prevent a successful result from being accepted and request cancellation of remaining work. A promise rejection alone does not establish that CPU-intensive decoding has stopped.

Hard resource deadlines require an implementation that can actually enforce them, such as isolated work with a termination boundary. Cooperative cancellation must be described as cooperative. A decoder that cannot be interrupted cannot become interruptible merely because an AbortSignal appears in the request type.

The service owns cleanup for resources it acquires. The UI still owns whether a result belongs to its current interaction and how the failure affects the user. Keeping those responsibilities explicit prevents a convenient API from promising more than its mechanisms deliver.

Pulling More Work Down Can Leak Product Policy

At this point, a request field such as screen: 'receipt' | 'avatar' may look like another simplification. The processor could choose dimensions, cropping, error messages, and upload permissions from the screen name.

The call becomes shorter, but the processor now needs to understand product screens. Changes to a layout or interaction may require edits to image infrastructure.

Pulling complexity downward can go too far. The work being absorbed should fit the module's existing responsibility, simplify consumers, and improve its interface. Moving unrelated application knowledge into a lower layer does not satisfy those conditions.

For this example, the processor can choose how to execute a requested transform. The calling feature should retain decisions about acceptable content loss, output intent, and what the user should experience when processing fails.

That boundary can support a small feature-specific helper such as createReceiptPreview without making the processor itself aware of receipts.

Review Configuration as a Transfer of Responsibility

For each proposed parameter, ask who can choose its value correctly, what evidence they would use, and what happens when it is omitted or wrong.

If the answer depends on decoder internals, exporting the parameter to every feature probably creates repeated guesswork. If the answer depends on the user's task or a deployment constraint the module cannot observe, an explicit option or focused override may be necessary.

For the receipt preview, keep dimensions, fit behavior, and the interaction budget in the request. Put decoder batching and allocation under maintained processor policy. Allow trusted deployment code to express genuine capacity constraints through the focused service setup.

The next person integrating the preview can then explain every value they supply. They ask for the whole receipt to remain visible, and the service takes responsibility for how that transform runs. That is a better API outcome than replacing five guesses with five copied constants.