Add transactional topic writer API for atomic table and topic operations #579
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.
Pull request type
What is the current behavior?
No built-in support for atomic operations spanning table modifications and topic publications. Developers must implement manual outbox patterns with background workers, adding complexity and operational burden.
What is the new behavior?
Introduces
CreateTxWriter<T>()onYdbConnectionto publish messages to topics within an ACID transaction. Messages become visible atomically with table changes after successful commit.API Surface
Implementation
ITxTopicWriter<T>: Public interface with voidWrite(T)methodTxWriterOptions: Configurable buffer size (default 64MB), producer ID, codec, partitionTxTopicWriter<T>: Internal buffering implementation with ConcurrentQueueYdbConnection.CreateTxWriter<T>(): Factory requiring active transactionYdbTransaction.CommitAsync(): Flushes all writers viaIInternalTxWriterinterface before commitTxTopicWriterException: Thrown on buffer overflow (non-blocking design)Buffer Overflow Strategy
Throws exception when buffer is full (default 64MB) rather than blocking producer thread. Safe for server workloads; caller controls backpressure through flush/retry/batch logic.
Current Limitations
Topic sending to YDB service is placeholder simulation. Production implementation requires WriterSession pooling, transaction ID binding in WriteRequest, and acknowledgement handling. API contract and integration points are production-ready.
Other information
Original prompt
This section details on the original issue you should resolve
<issue_title>Transactional Write to YDB Topic and Table (TxWriter API)</issue_title>
<issue_description># Summary
Introduces an API for publishing messages to a YDB topic within the same ACID transaction that modifies tables.
All messages written via
TxWriterare bound to the current transaction and become visible atomically together with table changes after a successful commit. Message sending is performed in the background while the application continues to work with tables or other topics. Before committing, theYdbConnectionwaits for acknowledgements of all pending messages, and then commits.Motivation
Proposed API (names are indicative)
Interfaces
Maybe unused interface:
YdbConnection
Usage example
Reference
Core Concepts
BeginTransactionmust be executed before sending (by the library).CreateTxWriteris onYdbConnection(it owns QuerySession and the transaction context) and binds the writer to the current txId.CreateTxWriterif none is active; starting on first Write is acceptable but must remain single and idempotent under concurrency.CreateTxWriterattaches to it; no new transaction is started.TxWriter: API design with void Write and buffer backpressure/overflow handling
Goal and context
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.