Design a Thread-Safe Shared Counter
Company: Citadel
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
Design and implement a per-key counter.
Requirements:
- Provide an API such as `incrementAndGet(key)`.
- Each call increments the count for that key and returns how many times that key has been called so far.
- Start with a simple in-process implementation.
- Make the implementation thread-safe.
- Compare multiple thread-safety approaches and their trade-offs.
- Extend the design to support multiple independent applications or processes running on the same host that all need to share the same counter values.
Quick Answer: This question evaluates understanding of concurrency, synchronization, shared-state management, and inter-process coordination by asking for a thread-safe per-key counter implementation in the Software Engineering Fundamentals domain.