Suppose there is a "User Segmentation Service" (USS) that segments users based on their activities. For example, if a user visits sports news, USS classifies and tags "sport" to him. So we have a pair: (the user_id, and the segment) for example, (u104010, "sports").
We want to develop an Estimation Service (ES) that interacts with USS directly. ES receives the pair from USS as input and stores it. The responsibility of ES is to answer a simple query: "How many users exist on a specific segment?". For example, "how many users are in the sports segment?".
The query is simple, but two assumptions may make it a little challenging:
- A specific user remains just two weeks on a segment. After that, we should not count "u104010" on the sports segment.
- There are millions of users and hundreds of segments. So your solution(s) must be scalable
- Implement a (REST API, RESTful API, soap, Graphql, RPC, gRPC, or whatever protocol you prefer) interface to receive data (user_id, segment pair) from USS.
- Implement a method to estimate the number of users in a specific segment. (
func estimate(segment) -> number of users
)
Try to write your code as reusable and readable as possible. Also, don't forget to document your code and clear the reasons for all your decisions in the code.
If your solution is not simple enough for implementing fast, you can just describe it in your documents.
Use any tools that you prefer just explain the reason of choices in your documents. For example explain why you choose REST API for receiving data.
It is more valuable to us that the project comes with unit tests.
Please fork this repository and add your code to that. Don't forget that your commits are so important. So be sure that you're committing your code often with a proper commit message.