Java Backend Screening Test – Set 7

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_IDNAME
1Laptop
2Phone
3Tablet

ORDERS

ORDER_IDPRODUCT_ID
1011
1021
1032

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 DELETE idempotent?
  • Is PATCH always 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:

  1. Reserve inventory.
  2. Charge payment.
  3. Shipping fails.
  4. Refund payment.
  5. Release inventory.

This restores business consistency without a distributed database transaction.


Question 6

Correct Answer: A

Explanation

LEFT JOIN returns all products.

Order counts:

ProductCount
Laptop2
Phone1
Tablet0

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

ApproachTimeSpace
Arithmetic SumO(n)O(1)
XORO(n)O(1)

Evaluation Guide

ScoreRecommendation
9/9Excellent – Strong Microservices Developer
7–8Good – Proceed to Technical Round
5–6Average – Requires Further Evaluation
Below 5Not 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 from groupingBy().
  • 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.

Leave a Reply

Your email address will not be published. Required fields are marked *