PhonePe
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-03-05Added By Anonymous
Source:Ā Link
š§ Experience: unknown
ā Outcome: unknown
š° Compensation: unknown
š Location: unknown
š¢ Company: PhonePe
š Education: unknown
š Benefits: unknown
š Offer Date: unknown
Level 1 - Current level Event-Aggregator Machine Coding Round All kinds of software services publish events. Event can be a transaction done by a user or it can be a user login. An "event aggregator" refers to a system or component within a software application that collects and combines data from various events based on predefined criteria. This type of event aggregator is commonly used in analytics, monitoring, or reporting systems where data from multiple events needs to be aggregated and analyzed for insights or decision-making purposes. Letās implement an Event aggregator with the following set of rules: Implement an event aggregator which can process ānā number of events and āmā types of events. Implement an event queue to queue the incoming events. The aggregator will process these events in the order that they are received. The queue should be in memory and should not require access to the file system. The aggregator should aggregate events in real time, i.e. the aggregate value should be calculated/ updated by the aggregator as soon as it receives the event. The aggregator should provide event filtering capabilities. (Process only those events that satisfy a predefined condition). The aggregator should provide a time-window support for controlling the scope of aggregations. Implement a ROLLING_WINDOW. ROLLING_WINDOW: A sliding time window where you want to set a range and always keep the range intact while moving forward in time. This is a time window that never collapses. For example, rolling_window(count(target_event), 5 mins, 1 min) ā counts the number of occurrences of a target event in the last 5 mins. After 1 mins, the count will be set to sum(count(2nd min), count(3rd min), count(4th min), count(5th min), count(6th min) ~ 0) Following is the expected schema for different type on events: eventType (String) timestamp (Date time format) eventData { key1: value1 key2: value2 key3: value3 ā¦ā¦ā¦ } The AggregationMeta table holds the metadata for the aggregations configured. Store this info in-memory for simplicity of the implementation. No need to connect to any database. To create a new aggregation, a new record needs to be created in the AggregationMeta table. Following is the schema for aggregation meta: aggregationName (String | unique) eventType (Event type of the event on which aggregation needs to be performed) aggregationType (enum: [ācountā, āsumā]) aggregationKey (String) aggregationField (Json path of field to be aggregated) timeInterval (integer | in mins) slideInterval (integer | in mins) filterRules (Rules to filter events to be considered for aggregation) (enum: [āeqā, āgtā, āltā]) Consider the following example for more clarity: Following are the āAPP_INSTALL_COMPLETEDā events for different users of app store: { āeventTypeā: āAPP_INSTALL_COMPLETEDā, ātimestampā: ā1706452811465ā, "eventData": { āappNameā: āapp1ā, āsourceā: āhomeā, āuserIdā: āu001ā , āspaceInMbā: 2 } } { āeventTypeā: āAPP_INSTALL_COMPLETEDā, ātimestampā: ā1706452811500ā, "eventData": { āappNameā: āapp2ā, āsourceā: āhomeā, āuserIdā: āu001ā, āspaceInMbā: 3 } } { āeventTypeā: āAPP_INSTALL_COMPLETEDā, ātimestampā: ā1706452811520ā, "eventData": { āappNameā: āapp2ā, āsourceā: āhomeā, āuserIdā: āu002ā, āspaceInMbā: 3 } } { āeventTypeā: āAPP_INSTALL_COMPLETEDā, ātimestampā: ā1706452811675ā, "eventData": { āappNameā: āapp3ā, āsourceā: āhomeā, "userIdā: āu002ā, āspaceInMbā: 4 } } SCENARIO 1: We need a total number of installs done by each user where spaceInMb size is greater than 2 in the last 5 mins. Following will be the aggregation record for the above example. { aggregationName: āinstallCountUserā, eventType: āAPP_INSTALL_COMPLETEDā, aggregationType: ācountā, aggregationKey: āeventData.userIdā, aggregationField: āeventData.spaceInMbā, timeInterval: 5, slideInterval: 1, filterRules: [ { āfieldā: āeventData.spaceInMbā, āopā: āgtā, āvalueā: 2 } ] } Following are the aggregations created for the above metadata: āu001ā: 1 āu002ā: 2 SCENARIO 2: If we need the total space utilized by each user to install all the apps. Following will be the aggregation metadata for this. { aggregationName: ātotalSpaceUserā, eventType: āAPP_INSTALL_COMPLETEDā, aggregationType: āsumā, aggregationKey: āeventData.userIdā, aggregationField: āeventData.spaceInMbā, timeInterval: 5, slideInterval: 1, filterRules: [] } Following are the aggregates created for the above metadata: āu001ā: 5 āu002ā: 7 Store these aggregates also in memory for simplicity purposes. These aggregates should not be computed in real time. All of them should be pre computed and just retrieved from memory when requested. Expected Interfaces: createMeta(AggregationMeta aggregationMeta) // Pass aggregation meta information to this function to create a new aggregation meta record Following is the sample input for this function { aggregationName: āinstallCountUserā, eventType: āAPP_INSTALL_COMPLETEDā, aggregationType: ācountā, aggregationKey: āeventData.userIdā, aggregationField: āeventData.spaceInMbā, filterRules: [ { āfieldā: āeventData.spaceInMbā, āopā: āgtā, āvalueā: 2 } ] } getAggregation(aggregationName, keyValue) // getAggregation(āinstallCountUserā, āu002ā) will give output as 2. Important note: This function should not calculate aggregation in real time. It should only get the pre-computed value stored in memory. Expectations Code should be working properly Separation of concerns Abstractions Application of OO design principles Testability Code readability [execution time limit] 4 seconds (js) [memory limit] 1 GB
ā Outcome: unknown
š° Compensation: unknown
š Location: unknown
š¢ Company: PhonePe
š Education: unknown
š Benefits: unknown
š Offer Date: unknown
Level 1 - Current level Event-Aggregator Machine Coding Round All kinds of software services publish events. Event can be a transaction done by a user or it can be a user login. An "event aggregator" refers to a system or component within a software application that collects and combines data from various events based on predefined criteria. This type of event aggregator is commonly used in analytics, monitoring, or reporting systems where data from multiple events needs to be aggregated and analyzed for insights or decision-making purposes. Letās implement an Event aggregator with the following set of rules: Implement an event aggregator which can process ānā number of events and āmā types of events. Implement an event queue to queue the incoming events. The aggregator will process these events in the order that they are received. The queue should be in memory and should not require access to the file system. The aggregator should aggregate events in real time, i.e. the aggregate value should be calculated/ updated by the aggregator as soon as it receives the event. The aggregator should provide event filtering capabilities. (Process only those events that satisfy a predefined condition). The aggregator should provide a time-window support for controlling the scope of aggregations. Implement a ROLLING_WINDOW. ROLLING_WINDOW: A sliding time window where you want to set a range and always keep the range intact while moving forward in time. This is a time window that never collapses. For example, rolling_window(count(target_event), 5 mins, 1 min) ā counts the number of occurrences of a target event in the last 5 mins. After 1 mins, the count will be set to sum(count(2nd min), count(3rd min), count(4th min), count(5th min), count(6th min) ~ 0) Following is the expected schema for different type on events: eventType (String) timestamp (Date time format) eventData { key1: value1 key2: value2 key3: value3 ā¦ā¦ā¦ } The AggregationMeta table holds the metadata for the aggregations configured. Store this info in-memory for simplicity of the implementation. No need to connect to any database. To create a new aggregation, a new record needs to be created in the AggregationMeta table. Following is the schema for aggregation meta: aggregationName (String | unique) eventType (Event type of the event on which aggregation needs to be performed) aggregationType (enum: [ācountā, āsumā]) aggregationKey (String) aggregationField (Json path of field to be aggregated) timeInterval (integer | in mins) slideInterval (integer | in mins) filterRules (Rules to filter events to be considered for aggregation) (enum: [āeqā, āgtā, āltā]) Consider the following example for more clarity: Following are the āAPP_INSTALL_COMPLETEDā events for different users of app store: { āeventTypeā: āAPP_INSTALL_COMPLETEDā, ātimestampā: ā1706452811465ā, "eventData": { āappNameā: āapp1ā, āsourceā: āhomeā, āuserIdā: āu001ā , āspaceInMbā: 2 } } { āeventTypeā: āAPP_INSTALL_COMPLETEDā, ātimestampā: ā1706452811500ā, "eventData": { āappNameā: āapp2ā, āsourceā: āhomeā, āuserIdā: āu001ā, āspaceInMbā: 3 } } { āeventTypeā: āAPP_INSTALL_COMPLETEDā, ātimestampā: ā1706452811520ā, "eventData": { āappNameā: āapp2ā, āsourceā: āhomeā, āuserIdā: āu002ā, āspaceInMbā: 3 } } { āeventTypeā: āAPP_INSTALL_COMPLETEDā, ātimestampā: ā1706452811675ā, "eventData": { āappNameā: āapp3ā, āsourceā: āhomeā, "userIdā: āu002ā, āspaceInMbā: 4 } } SCENARIO 1: We need a total number of installs done by each user where spaceInMb size is greater than 2 in the last 5 mins. Following will be the aggregation record for the above example. { aggregationName: āinstallCountUserā, eventType: āAPP_INSTALL_COMPLETEDā, aggregationType: ācountā, aggregationKey: āeventData.userIdā, aggregationField: āeventData.spaceInMbā, timeInterval: 5, slideInterval: 1, filterRules: [ { āfieldā: āeventData.spaceInMbā, āopā: āgtā, āvalueā: 2 } ] } Following are the aggregations created for the above metadata: āu001ā: 1 āu002ā: 2 SCENARIO 2: If we need the total space utilized by each user to install all the apps. Following will be the aggregation metadata for this. { aggregationName: ātotalSpaceUserā, eventType: āAPP_INSTALL_COMPLETEDā, aggregationType: āsumā, aggregationKey: āeventData.userIdā, aggregationField: āeventData.spaceInMbā, timeInterval: 5, slideInterval: 1, filterRules: [] } Following are the aggregates created for the above metadata: āu001ā: 5 āu002ā: 7 Store these aggregates also in memory for simplicity purposes. These aggregates should not be computed in real time. All of them should be pre computed and just retrieved from memory when requested. Expected Interfaces: createMeta(AggregationMeta aggregationMeta) // Pass aggregation meta information to this function to create a new aggregation meta record Following is the sample input for this function { aggregationName: āinstallCountUserā, eventType: āAPP_INSTALL_COMPLETEDā, aggregationType: ācountā, aggregationKey: āeventData.userIdā, aggregationField: āeventData.spaceInMbā, filterRules: [ { āfieldā: āeventData.spaceInMbā, āopā: āgtā, āvalueā: 2 } ] } getAggregation(aggregationName, keyValue) // getAggregation(āinstallCountUserā, āu002ā) will give output as 2. Important note: This function should not calculate aggregation in real time. It should only get the pre-computed value stored in memory. Expectations Code should be working properly Separation of concerns Abstractions Application of OO design principles Testability Code readability [execution time limit] 4 seconds (js) [memory limit] 1 GB