Design a Large JSON and XML Transformation Service
Design a bounded-memory service that transforms a 300 GB JSON array on one 16 GiB, 8-core worker with durable job control and monitoring. Add a finite independent-record XML profile with explicit parser limits and restart context while preserving the JSON interface.
Problem statement
For the preserved JSON practice profile, assume a service transforms one 300 GB top-level JSON array on a machine with 16 GiB of RAM and 8 CPU cores. The service must include job submission, a status API, and monitoring.
For this exercise, assume the input and output are uncompressed objects in durable storage that supports range reads and multipart writes. A submitted job names a registered deterministic transformation that can process each array element independently.
The output must be a valid JSON array whose elements remain in input order. Run at most one job on the worker while excess jobs wait durably. Status progress may lag actual processing by up to 10 seconds.
A retry resumes at a durable element boundary and no partial output becomes the final object; only one successful attempt may publish the result.
Arbitrary user code, compressed input, joins across elements, distributed execution across multiple machines, and transformation-specific business logic are outside scope.
Explain bounded-memory parsing, use of the 8 cores, backpressure, ordering, checkpoints, retries, cancellation, final publication, and operational visibility.
For this exercise, also admit a versioned XML profile on the same one-machine data path. Its UTF-8 document has one unnamespaced records root containing zero or more ordered record subtrees.
Inside each record, field elements form a finite tree with escaped text at leaf fields; nonempty records contain field children, and empty record or field elements are allowed. Whitespace-only separators between child elements are permitted; nonwhitespace text may not mix with child elements.
Attributes, namespaces, XML declarations, comments, processing instructions, CDATA, DTDs, numeric character references and entity declarations are outside this profile; only the five predefined XML text entities are admitted.
Limit nesting within a record to 64 levels, counting record itself as level one, one encoded scalar token to 1 MiB, and each serialized input and output record to 8 MiB.
A registered deterministic transform produces exactly one valid record per input record, independently of other records, with at most 32 MiB of declared working scratch per active transform. The output is one complete records document in input order.
For this XML profile, choose a 300 GB practice input and keep application-managed parse, active-transform, reorder and writer buffers within a declared 2 GiB budget, leaving headroom on the 16 GiB host. Neither this size/hardware nor the XML grammar or limits is a recalled XML-source measurement.
Validate supported grammar and resource limits while streaming; malformed, unsupported or oversized data has an explicit failed outcome with location and no final output. Submission binds the format-profile version; omitted format keeps the existing JSON profile.
Logical progress may be durable even when a parser must replay an earlier input prefix.
An XML restart must restore valid parser context rather than jump to an arbitrary byte offset.
A complete-record checkpoint may use a proven parser-state boundary; alternatively, preserve a durable sequence-tagged record spool and replay the immutable XML prefix from the beginning to validate context and identify the last committed record before continuing. Replaying does not duplicate logical output.
The document root must close and all records/output must validate before fenced publication. Temporary local spill is bounded and disposable; required resume evidence is durable. Distributed processing and arbitrary XML with cross-record dependencies remain excluded.
What to build
- A client can idempotently submit an input object, output destination, and registered transformation and receive a durable job identifier. A format-profile version is part of the logical request; omitting it preserves the existing JSON default.
- The worker transforms every element of the 300 GB top-level JSON array with bounded memory and publishes one valid, input-ordered output array. For the XML profile, transform every validated independent record under its finite grammar and resource limits, and publish one complete input-ordered records document.
- A client can read queued, running, retrying, cancelled, succeeded, or failed status together with bounded-lag progress and an output or error reference. Distinguish parser replay from new durable record/output progress and report malformed, unsupported or resource-limit failures with location.
- A client can request cancellation and can retry a failed attempt without exposing partial output or allowing a stale attempt to publish.
At scale
- For the preserved authored JSON practice profile, assume one 300 GB top-level JSON array on a machine with 16 GiB of RAM and 8 CPU cores.
- For this exercise, assume the input and output are uncompressed objects in durable range-readable and multipart-write storage.
- For this exercise, assume one active job per worker, durable queueing for excess jobs, and client-visible progress that may lag processing by at most 10 seconds.
- For this exercise, assume ordered output, durable resume at element boundaries, and atomic publication of the single winning completed attempt.
- For the authored XML profile, assume a 300 GB UTF-8 document, 64-level record nesting, a 1 MiB encoded scalar-token limit and 8 MiB input/output-record limits; registered transform scratch is at most 32 MiB per active transform. Keep application-managed live buffers within 2 GiB, and use at most the existing eight cores under backpressure. These are finite practice choices, not XML-source hardware or size facts.