Round 1
Questions: Design and implement a user journey service for monitoring users as they navigate through various use cases. This will be a rule-based journey framework where a user will onboard a journey and move along various stages on the basis of specific conditions.
Requirements:
- Journey is a Directed Acyclic Graph (DAG) that represents a predefined path to track a user on.
- A journey consists of 'n' stages, and users must complete specific actions/events to advance to the next stage.
- Multiple users can onboard to the same journey.
- A user can onboard a journey only once.
- Complete isolation across different journeys.
- Journeys can be of 2 types: time-bound (having a start-date, end-date) and perpetual (no validity).
- The first stage in the journey will be the onboarding stage, middle stages will be onward stages, and the final stage will be the terminal stage.
- A journey must be marked as active to be evaluated; by default, it should be inactive.
- Time-bound journeys should be marked inactive when the validity period is over.
Example:
- J1: Stage 1 -> Stage 2 -> Stage 3. Onboarding step for Stage 1 is login. For stage 2 is user opening recharge page and Stage 3 is user doing a recharge transaction.
- J2: Stage 1 -> Stage 2. Onboarding step is the user opening a UPI lite account. For stage 2 is the user doing a top-up on their UPI lite account.
Users:
- User 1: Logins to the app, hence is on stage 1 of J1. User opens the recharge page, moves to stage 2 of J1.
- User 2: Logins to the app, hence is on stage 1 of J1. User opens the recharge page, moves to stage 2 of J1, then does a recharge transaction, moves to stage 3 of J1.
- User 3: Logins to the app, hence is on stage 1 of J1. User opens a UPI account and is onboarded to J2.
Mandatory Implementations:
createJourney(Journey journey)
updateState(String JourneyId, boolean active)
getJourney(String journeyId)
evaluate(String userId, Payload payload)
getCurrentStage(String userId, String journeyId)
isOnboarded(String userId, String journeyId)
Optional:
- Send SMS to a user on stage transition.
- Support for recurring journeys.
System Architecture:
- Events flow to a message queue, and the journey service acts as a consumer, evaluating messages and tracking user and journey status.
Points to note:
- Code should cover all mandatory functionalities.
- Executable and clean code.
- Necessary validations must be present.
- Proper error codes in case of exceptions.
- Store data in-memory for journeys and user transitions.
Evaluation Criteria:
- Code functionality.
- Readability and testability.
- Separation of concerns.
- Object-oriented concepts.
- Language proficiency.
- SOLID principles.
The round was of 1.5 hours, and you had to write the code and submit it via email as a zip file.
Candidate's Approach
The candidate designed a service that utilizes a Directed Acyclic Graph (DAG) to represent user journeys. They implemented the mandatory functions to create journeys, update their states, and evaluate user transitions based on payload conditions. The approach included in-memory storage for journeys and user transitions, ensuring efficient tracking and state management.
Interviewer's Feedback
The interviewer appreciated the candidate's understanding of the requirements and the clean structure of the code. They suggested improvements in error handling and emphasized the importance of adhering to SOLID principles for better maintainability.