1. Walk us through how you would design a REST API for a payment transaction service that handles concurrent requests and ensures idempotency. What Spring components would you use?
I'd use Spring REST controllers with request mapping, implement idempotency through unique transaction IDs stored in a database with a unique constraint, and leverage Spring's @Transactional annotation to ensure atomicity; for example, checking if a transaction ID exists before processing prevents duplicate charges from retry requests.
2. Describe a situation where you used the Dependency Injection pattern in a Spring application. How did it improve testability?
I refactored a payment processor service to inject a PaymentGateway interface rather than instantiating it directly, allowing tests to inject a mock implementation; this eliminated hard dependencies on the real gateway and reduced test execution time from 2 minutes to 10 seconds.
3. You're debugging a Spring service where a Singleton bean is showing inconsistent state across requests. What could be wrong, and how would you fix it?
The singleton likely stores mutable state as instance variables; the fix is to use thread-local storage, method parameters, or change the bean scope to @Scope('prototype') if isolation is needed; for example, moving a request-specific User object from an instance field to a method parameter prevents cross-request contamination.
4. Walk through how you would write unit, service, and integration tests for a payment transaction endpoint. What test framework and mocking libraries would you use?
Unit tests with JUnit and Mockito would isolate the transaction business logic mocking the database layer, service tests would use an embedded database like H2, and integration tests would spin up a test Spring context hitting real or containerized dependencies; for example, unit tests verify fee calculation logic while integration tests confirm end-to-end payment recording.
5. Explain the Observer pattern and provide an example of when you've used it in a Spring application. How does it differ from an event-driven architecture?
The Observer pattern has objects register callbacks to be notified of state changes; I used Spring's @EventListener to trigger email notifications when a payment succeeded, decoupling the payment service from email logic, whereas full event-driven architecture routes events through message brokers enabling async processing across services.
6. Design a backend service that processes batch payment files uploaded daily. How would you structure it, what patterns would you consider, and how would you ensure it's reliable?
I'd create a batch job using Spring Batch with a reader to parse the file, processor to validate and transform records, and writer to persist results; to ensure reliability I'd implement error handling per record with dead-letter queues, idempotent writes with transaction IDs, and monitoring to alert on failed batches or partial completions.
7. You're refactoring a legacy payment module with tight coupling. How would you apply the Adapter pattern to integrate a new payment gateway without breaking existing code?
I'd create an adapter class implementing the existing PaymentProcessor interface but delegating calls to the new gateway's API, allowing old code to use new logic transparently; for example, an AlternateGatewayAdapter wraps the new gateway and translates its response format to match the legacy interface.
8. Describe a time when you had to optimize a slow SQL query in a Spring application. What was your approach and what tools did you use?
I discovered an N+1 query problem in a transaction lookup endpoint using Spring's query logging; I fixed it by adding @EntityGraph annotation to eagerly load related merchant and account entities in a single query, reducing database round-trips from 50 to 1 and cutting response time from 800ms to 150ms.
9. How would you implement a secure API endpoint for transferring funds between accounts? What security measures would you implement at the backend level?
I'd use HTTPS/TLS for transport encryption, validate authentication tokens, implement authorization checks to ensure the requester owns the source account, use parameterized queries to prevent SQL injection, and log all transfers for audit trails; additionally I'd implement rate limiting and transaction signing to prevent tampering.
10. Explain the Factory pattern and show how you'd use it to create different payment processor implementations. When is it better than Spring's @Bean approach?
Factory pattern centralizes object creation logic, so a PaymentProcessorFactory would instantiate the correct processor based on payment method; it's useful when creation logic is complex or dynamic, whereas @Bean is simpler for static Spring-managed beans since Spring handles lifecycle automatically.
11. You need to build an event-driven service where payment events trigger downstream processes like fraud detection and reporting. Walk us through the architecture.
I'd publish payment events to a message broker like Kafka, with separate microservices subscribing to these topics: a fraud detection service consuming and analyzing transactions, a reporting service aggregating metrics, and a notification service sending alerts; each service handles events asynchronously, allowing the payment API to respond quickly without waiting for downstream processing.
12. Walk us through how you'd approach building a React frontend to consume a Spring backend API for displaying transaction history. What considerations would you make on the backend?
I'd design a REST endpoint returning paginated transaction data with filtering by date range and status, implement CORS policies to allow frontend requests, consider API versioning for backward compatibility, and add request validation and error responses with meaningful codes; on the frontend I'd handle loading states and pagination, but the backend must support efficient querying and proper error semantics.



