Add opt-in Cosmos Binary encoding for Direct item, query, and batch operations#49834
Draft
JulienEllie wants to merge 5 commits into
Draft
Add opt-in Cosmos Binary encoding for Direct item, query, and batch operations#49834JulienEllie wants to merge 5 commits into
JulienEllie wants to merge 5 commits into
Conversation
added 4 commits
July 15, 2026 16:00
Implement the Cosmos Binary value format, Jackson tree bridging, native binary scalars, compressed values, strict UTF-8 decoding, bounded nesting, and hostile-input validation.
Implement the fixed Cosmos BatchOperation and BatchResult schemas, RecordIO framing, CRC validation, exact .NET golden vectors, response-count bounds, and a single internal facade.
Add the Direct-mode feature gate and integrate Cosmos Binary with point operations, transactional batches, and bulk. Preserve HybridRow responses, decode structured batch results, size requests from encoded records, and retain JSON behavior for Gateway mode.
Describe the hidden Direct-mode opt-in, supported operation set, and native binary payload benefit.
Contributor
|
Thank you for your contribution @JulienEllie! We will review the pull request and get back to you soon. |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 30 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@microsoft-github-policy-service agree company="Walmart Inc." |
|
Commenter does not have sufficient privileges for PR 49834 in repo Azure/azure-sdk-for-java |
Author
|
@microsoft-github-policy-service agree company="Walmart Inc." |
Contributor
|
@JulienEllie the command you issued was incorrect. Please try again. Examples are: and |
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds opt-in Cosmos Binary encoding for Direct-mode document operations to avoid JSON/base64 expansion for native binary item fields.
Enable with either:
The feature is disabled by default and does not change the public item or serializer APIs.
Protocol background
Cosmos Binary documents use the
0x80format marker and support native binary scalar values rather than representingbyte[]as JSON base64 strings.Transactional batch and bulk use the service's existing wire contract:
This PR implements only the fixed Cosmos batch schemas; it does not add a general-purpose HybridRow engine.
Supported operations
readAllItemsContentSerializationFormat; live validatedPre-serialized JSON
byte[]inputs are parsed and re-encoded before a request advertises Cosmos Binary. Existing0x80input remains unchanged. CustomCosmosItemSerializerhooks, ID validation, tracking IDs, diagnostics, retry bytes, session tokens, and content-response-disabled behavior remain in their existing paths.Explicit remaining gap: generic raw ReadFeed
Generic raw
OperationType.ReadFeedremains text. This does not include partition-scoped publicreadAllItems, which Java implements as a SQL query and therefore receives binary query responses.This boundary follows the service behavior documented and tested by the .NET SDK:
SupportedSerializationFormatsforOperationType.Queryand documents partition-key ReadFeed binary responses as a backend bug.ContentSerializationFormatcontract, which this PR mirrors.Relying on the documented backend bug would make behavior partition- and routing-dependent, so generic raw ReadFeed is intentionally excluded pending a supported service contract. No matching Java issue currently documents this limitation; a follow-up issue can track it if the service adds stable negotiation.
Parser and wire hardening
The implementation includes:
Unsupported user-dictionary string markers require out-of-band dictionary state and are rejected. Normal supported service responses do not provide such a dictionary.
Validation
Focused Failsafe coverage currently passes:
Coverage includes marker/golden vectors, every-marker handling, truncation at every byte boundary, hostile lengths/counts, strict UTF-8, native Jackson binary nodes, custom serializer behavior, RNTBD format tokens, exact .NET HybridRow vectors, CRC failures, duplicate sparse fields, and exact batch size boundaries.
Live Direct-mode validation against Azure Cosmos DB covered:
AVAD uses the same binary response selection and parser path, but remains explicitly not live validated due to the lack of an AVAD-enabled account.
Spotless and
git diff --checkpass. Meaningful Revapi validation should run under the repository-supported JDK in CI; locally available JDK 25/26 trigger unrelated Revapi scanner failures.Preliminary size/performance evidence
Directional local measurements for documents dominated by 8, 64, and 256 KiB binary fields showed approximately:
These timings are preliminary and are not presented as JMH benchmark results or universal document-size guarantees.
Risk and rollback
The feature is disabled by default and restricted to Direct document paths. Removing the environment variable or JVM property restores existing JSON behavior without application changes.
Reviewer guide
Add Cosmos binary JSON codec— value encoding/decoding and hostile-input validation.Add HybridRow batch wire codec— fixed batch schemas and RecordIO framing.Enable opt-in Cosmos binary encoding— serializer, point, query, Change Feed, batch, bulk, and RNTBD integration.Document Cosmos binary encoding— changelog and supported scope.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines