Engineering With Java

Engineering With Java

Spring Boot Interview Question: Batch Transaction Compaction

Code examples, interview, design and more ...

Suraj Mishra's avatar
Suraj Mishra
Feb 23, 2026
∙ Paid

Background

You are working on a Spring Boot–based payment processing system.

The system receives batches of transaction IDs from upstream services.
Each batch is represented as an integer array.

  • A value of 0 represents an invalid or failed transaction

  • A non-zero value represents a valid transaction

Before forwarding the batch to a downstream settlement service, the system must:

  1. Process all valid transactions first

  2. Move all invalid transactions (0) to the end

  3. Preserve the original order of valid transactions

  4. Perform the operation in-place to avoid extra memory usage

Task

Implement a Spring Boot service that:

  • Accepts a batch of transactions via a REST endpoint

  • Reorders the batch according to the rules above

  • Returns the processed batch

For example,

Request Body:
[0, 1045, 0, 2099, 3301]

Response:
[1045, 2099, 3301, 0, 0]

📢 Get actionable Java/Spring Boot insights every week — from practical code tips to real-world use-case based interview questions.

Join 5500+ subscribers and level up your Spring & backend skills with hand-crafted content — no fluff.

First 100 paid subscribers will get the annual membership at $50/year ( 67 already converted to paid, 33 remaining )

So far we have covered 46+ real world based interview questions and will add up to 100 by end of this year.

Not convinced? Check out the details of the past work


Solution

Endpoint:

Logic:

  • Create a new array

  • First, copy all valid transactions

  • Then append non-valid transactions

  • Return the new array

User's avatar

Continue reading this post for free, courtesy of Suraj Mishra.

Or purchase a paid subscription.
© 2026 Suraj Mishra · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture