Java Microservice Consultant Interview Experience: Questions and In-Depth Answers
If you're preparing for a Java Microservice Consultant role at any service-based/Big 4 firm, it's essential to understand the range and depth of questions you might face. Below, I provide detailed answers and explanations.
Technical Round 1
1. Project Architecture, Modules, and Responsibilities
Explanation:
Be ready to explain your project's overall design—how modules interact, their responsibilities, and your contributions. Discuss layers (controller, service, repository), major workflows, and scaling/maintenance strategies.
2. Java: Immutability, Mutable & Immutable Strings, Real-world Use Case
Immutable Objects:
- Their state can't change after creation.
- Example: String
in Java is immutable.
Mutable Objects:
- Their state can change.
- Example: StringBuilder
is mutable.
Real-world Use Case:
Immutability is crucial for thread safety. For example, using String
as a key in HashMap is reliable because its value won't change, preventing issues with hash code calculations.
3. Threads: Ways to Implement & Lifecycle
Ways to create a thread:
- Extend Thread
class
- Implement
Runnable
interface- Implement
Callable<V>
interface (for threads that return results)Thread Lifecycle:
- New
- Runnable
- Running
- Blocked/Waiting
- Terminated
4. Transaction Management and Handling Rollback on Exception
Explanation:
In frameworks like Spring, use @Transactional
annotation. If an exception occurs, the transaction manager undoes all operations (rollback), ensuring data consistency.
5. Java 8: Streams, Lambdas, Functional Interfaces
- Streams: Declarative processing of collections.
employees.stream().filter(e -> e.getAge() > 25).collect(Collectors.toList());
- Lambdas: Concise syntax for anonymous functions.
(a, b) -> a + b
- Functional Interface: Interface with a single abstract method (e.g.,
Runnable
,Comparator
).
6. Sort Employee Objects Using Java 8 & Comparator
Explanation:
Use Comparator.comparing()
and stream API:
employees.stream() .sorted(Comparator.comparing(Employee::getSalary)) .collect(Collectors.toList());
7. SQL: Find Employee with 3rd Highest Salary
Query:
SELECT DISTINCT salary FROM Employee ORDER BY salary DESC LIMIT 1 OFFSET 2;
Or, using subquery:
SELECT MIN(salary) FROM (SELECT DISTINCT salary FROM Employee ORDER BY salary DESC LIMIT 3) AS temp;
8. Microservices vs Monolith – Advantages and Use Cases
Monolith | Microservices | |
---|---|---|
Structure | Single codebase | Multiple loosely-coupled services |
Scalability | Vertical (harder) | Horizontal (easier, per service) |
Deployment | All-or-nothing | Independent services |
Use Case | Small apps, POCs | Large, dynamic, scalable systems |
Advantages of microservices: Faster deployment, isolated failures, independent scaling.
9. How to Create a Microservice, Tools Used, and Monitoring
- Creation: Spring Boot to build lightweight RESTful services.
- Tools Used: Spring Boot, Docker, Kubernetes, Eureka, Zuul.
- Monitoring: Use tools like Prometheus, Grafana, Spring Actuator, ELK stack, or Zipkin for distributed tracing.
10. Coding Standards and Checklist
- Code readability
- Proper naming conventions
- Error handling
- Logging
- Unit tests
- Documentation
Technical Round 2
1. JVM vs JRE vs JDK
JVM | JRE | JDK |
---|---|---|
Java Virtual Machine | Java Runtime Env. | Java Dev Kit |
Runs Java bytecode | JVM + libs for running | JRE + dev tools |
Platform-dependent | Platform-dependent | Platform-dependent |
2. Ways to Create a String & Their Storage
- Literal (e.g., "hello"): Stored in String pool.
- Using
new String()
: Created in heap, not pooled automatically.
3. Interthread Communication: wait()
, notify()
, Why in Object Class
wait()
, notify()
are in Object
class because every Java object has a monitor (intrinsic lock) that threads can synchronize on. This allows any object—not just threads—to be used for interthread communication.
4. Design Patterns: Singleton Implementation and Usage
Singleton Implementation:
public class Singleton { private static Singleton instance; private Singleton() {} public static Singleton getInstance() { if (instance == null) { instance = new Singleton(); } return instance; } }
Real-time Use: Connection pools, logging, configuration managers.
5. Code: Connection Pool (Fixed Size, Acquire/Release)
Maintain a pool of connections using a collection (e.g., BlockingQueue). Provide methods to acquireConnection()
and releaseConnection()
. Ensure thread safety using synchronization or concurrent collections.
6. Spring Boot: Configure Multiple Databases
- Define two
DataSource
,EntityManagerFactory
, andTransactionManager
beans—one for each database.
7. Rollback Strategies Post Commit
After a commit, it's generally not possible to rollback at the database level. Can compensate by writing compensating transactions (SAGA pattern in microservices).
8. Project Testing, Deployment & Production Issue Debugging
- Testing: JUnit, Mockito, integration tests
- Deployment: CI/CD, Docker, Kubernetes
- Debugging: Analyze logs, use monitoring tools, replicate issues locally
Managerial Round
1. Detailed Project Discussion
Be ready to talk about your ownership, impact, team interaction, and architectural decisions.
2. Java Collections: List, Set, Map—Usage
- List: Ordered collection, allows duplicates (use: ordered data)
- Set: Unordered, no duplicates (use: unique items like user IDs)
- Map: Key-value pairs (use: dictionary, lookup tables)
3. Why Set Doesn't Allow Duplicates? What if I Add One?
A Set enforces uniqueness by comparing objects using equals()
and hashCode()
. If you add a duplicate, the set ignores the insertion.
4. Cloud Concepts: IAM, EC2, S3
- IAM: Manage users and permissions
- EC2: Virtual servers in AWS cloud
- S3: Object storage for files, backups, etc.
5. Exception Handling: Custom Exceptions & User-Friendly Messages
- Create subclasses of
Exception
orRuntimeException
.
6. Coding (Notepad): RESTful Person API (id, name, gender Enum)
Implement Controller, Service, Repository, and Model classes with a Gender
enum type. Expose CRUD endpoints.
7. SQL: Get Manager Names from Employee Table (empId, name, mgrId)
Query:
SELECT DISTINCT mgr.name FROM Employee emp JOIN Employee mgr ON emp.mgrId = mgr.empId;
8. Logical Puzzle: Room with 100 Switches—Efficient Way to Find Your Light (O(logN))
Use a binary search strategy. Assume each room has a unique light indicator per switch position. Flip switches in halves, observe changes, and narrow down to your room in log₂(100) ≈ 7 tries (binary search method).
Final Takeaway
Like other top-tier consultancies, tests both technical knowledge and the ability to apply concepts to real-world scenarios. Focus on problem-solving, communication, and clarity, not just technical correctness. Good luck on your interview journey!