Microservices | REST | Event-Driven Architecture | Resilience | SQL | Programming
Duration: 20 Minutes
Experience: 5–10 Years
This assessment evaluates concepts commonly encountered in cloud-native Java microservices, including REST design, asynchronous messaging, resiliency patterns, distributed transactions, SQL, and Java 8 programming.
Section A – Microservices MCQs (5 Questions)
Question 1 – Idempotent REST APIs
Which HTTP method is always expected to be idempotent?
A. POST
B. PUT
C. PATCH
D. CONNECT
Question 2 – Event-Driven Communication
Which scenario is best suited for asynchronous messaging?
A. User login requiring an immediate response
B. Credit card payment authorization
C. Sending welcome emails after successful registration
D. Validating login credentials
Question 3 – Circuit Breaker
What is the primary purpose of a Circuit Breaker?
A. Encrypt API requests
B. Prevent repeated calls to an unhealthy downstream service
C. Improve database indexing
D. Replace API Gateway
Question 4 – Retry Pattern
Which statement is TRUE about retries?
A. Every failure should be retried immediately and indefinitely.
B. Retries should generally be limited and use exponential backoff.
C. Retries are useful only for database failures.
D. Retries should be used for all HTTP 4xx responses.
Question 5 – Distributed Transactions
In a Saga pattern, how is consistency maintained when one of the later steps fails?
A. Global database rollback across all services
B. JVM rollback
C. Compensating transactions undo previously completed business operations
D. Restart all participating services
Section B – SQL Challenge
Question 6
Tables
PRODUCT
| PRODUCT_ID | NAME |
|---|---|
| 1 | Laptop |
| 2 | Phone |
| 3 | Tablet |
ORDERS
| ORDER_ID | PRODUCT_ID |
|---|---|
| 101 | 1 |
| 102 | 1 |
| 103 | 2 |
Query
SELECT P.NAME,
COUNT(O.ORDER_ID)
FROM PRODUCT P
LEFT JOIN ORDERS O
ON P.PRODUCT_ID = O.PRODUCT_ID
GROUP BY P.NAME
ORDER BY COUNT(O.ORDER_ID) DESC;
Which output is correct?
A.
Laptop 2
Phone 1
Tablet 0
B.
Laptop 2
Phone 1
C.
Phone 1
Laptop 2
Tablet 0
D.
Compilation Error
Section C – Programming Questions
Question 7 – Count Words
Write a Java program to count the occurrence of every word in a sentence.
Example
Java Spring Java Boot Spring Java
Expected Output
Java -> 3
Spring -> 2
Boot -> 1
Bonus:
Solve using Java 8 Streams.
Question 8 – Partition Numbers
Given
List<Integer> list =
Arrays.asList(2,5,7,8,10,13,14);
Using Java 8 Streams, partition the numbers into Even and Odd.
Expected Output
Even -> [2,8,10,14]
Odd -> [5,7,13]
Question 9 – Find Missing Number
Given an array containing numbers from 1 to n with one number missing, write a Java program to find the missing number.
Example
1 2 3 5 6
Expected Output
4
Bonus:
Provide both an arithmetic-sum solution and an XOR-based solution.
Answer Key & Detailed Explanations
Question 1
Correct Answer: B
Explanation
PUT replaces the entire resource. Sending the same request multiple times should leave the resource in the same final state.
POST is generally not idempotent, as repeated requests can create multiple resources.
Interview Follow-up
- Is
DELETEidempotent? - Is
PATCHalways idempotent?
(Expected answer: DELETE is intended to be idempotent. PATCH may or may not be, depending on implementation.)
Question 2
Correct Answer: C
Explanation
Welcome emails do not require an immediate response to the client.
Publishing an event allows the registration service to respond quickly while an email service processes the notification asynchronously.
Examples:
- Kafka
- RabbitMQ
- Amazon SNS/SQS
- Solace
Question 3
Correct Answer: B
Explanation
A Circuit Breaker prevents repeatedly calling a failing dependency.
Typical states:
- Closed
- Open
- Half-Open
This protects the application from cascading failures and allows downstream services time to recover.
Question 4
Correct Answer: B
Explanation
Retries should:
- Have a maximum retry count.
- Use exponential backoff.
- Include jitter in distributed environments to avoid retry storms.
Retries are appropriate mainly for transient failures (timeouts, temporary network issues), not for permanent errors such as most HTTP 4xx responses.
Question 5
Correct Answer: C
Explanation
Microservices typically do not share a global transaction manager.
Instead, the Saga pattern uses compensating actions.
Example:
- Reserve inventory.
- Charge payment.
- Shipping fails.
- Refund payment.
- Release inventory.
This restores business consistency without a distributed database transaction.
Question 6
Correct Answer: A
Explanation
LEFT JOIN returns all products.
Order counts:
| Product | Count |
|---|---|
| Laptop | 2 |
| Phone | 1 |
| Tablet | 0 |
The ORDER BY COUNT(...) DESC clause sorts the results by order count in descending order.
Question 7 – Sample Solution
Arrays.stream(sentence.split(" "))
.collect(Collectors.groupingBy(
Function.identity(),
LinkedHashMap::new,
Collectors.counting()))
.forEach((k,v) ->
System.out.println(k + " -> " + v));
Concepts Tested
groupingBy()Function.identity()counting()LinkedHashMap
Complexity
Time: O(n)
Space: O(n)
Question 8 – Sample Solution
Map<Boolean,List<Integer>> result =
list.stream()
.collect(Collectors.partitioningBy(
n -> n % 2 == 0));
System.out.println("Even -> " + result.get(true));
System.out.println("Odd -> " + result.get(false));
Concepts Tested
partitioningBy()- Predicate
- Streams
Complexity
Time: O(n)
Space: O(n)
Question 9 – Sample Solution
Arithmetic Sum
int n = 6;
int expected = n * (n + 1) / 2;
int actual = Arrays.stream(arr).sum();
System.out.println(expected - actual);
XOR Approach
int xor = 0;
for(int i = 1; i <= n; i++){
xor ^= i;
}
for(int value : arr){
xor ^= value;
}
System.out.println(xor);
Complexity
| Approach | Time | Space |
|---|---|---|
| Arithmetic Sum | O(n) | O(1) |
| XOR | O(n) | O(1) |
Evaluation Guide
| Score | Recommendation |
|---|---|
| 9/9 | Excellent – Strong Microservices Developer |
| 7–8 | Good – Proceed to Technical Round |
| 5–6 | Average – Requires Further Evaluation |
| Below 5 | Not Recommended |
Interviewer’s Notes
This set evaluates architectural thinking rather than API memorization.
A strong candidate should be able to explain:
- Why idempotency matters in distributed systems.
- When asynchronous messaging is preferable to synchronous REST calls.
- How Circuit Breakers prevent cascading failures.
- Why retries need exponential backoff and jitter.
- How Saga patterns maintain consistency without distributed transactions.
- How
partitioningBy()differs fromgroupingBy(). - The advantages of the XOR solution over arithmetic summation for the missing-number problem.
Candidates who discuss failure scenarios, duplicate message handling, dead-letter queues (DLQs), and idempotent consumers demonstrate practical experience with event-driven systems.