StartUp Interview Question for Analysts


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

This is a design pattern question.

As far as I can see multiple patterns can be use for designing. One of my best bet is Observer design pattern.

Every day a client application (each uber picks up a client), it stores its users info in its local system or update to secondary system.
Your Dash acts as an observers and collects the subject info and churn out the data.

Now, to handle this kinda question depends upon you comfort in pattern understanding as question like this may takes a lot of time to address in short interviews and interviewer is basically looking for your understanding then correct answer. (There is no wrong answer to such questions as far as you can argue your pattern is correct).

Implementation should be straight forward once you know the pattern.

- hprem991 July 26, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

More to do with big data. Storing all possible data in carefully designed database and tables. Use UI to query the relevant data using SQL

- Satish July 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

But the question is mostly for real time .. so where we cannot have a dashboard to work as observer pattern. we can choose mvvp / mvc for UI . and at back end , we have use loadbalancers and servers use some hashmaps to get the required details ..
we can use pub/sub patterns while pushing to servers etc.

- gopi.komanduri July 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Millions of updates per second can be handled by a high throughput distributed messaging system like Kafka.
For high scalability, use an intermediary data processing task (e.g. a job in Spark Streaming) to perform first level aggregations on the incoming data.
The message contains all the information for a trip id. This data can be aggregated to a sub-total for a batch, e.g. day, hour, min, city, total trips, total fare, total new users.
The sub-totals can be stored in RDBMS, queries run on this to populate the dashboard. Frequency of queries should be high, < 5 min to achieve the realism.
The queries should update tables in the DB which the dashboard then reads for low latency.

All existing users can be stored in a hash or a DB table, an interesting question is what is a new user? The same person might create a new ID.

- colin August 03, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Introduce a kafka server between the data coming from server(devices of driver will send request to server in the form of s1,s2).
2. Each ride message will be sent in the topic created in Kafka.
3. Topic is partitioned based on the city, so that consumers can consume the data in a multi-threaded fashion.
4. These consumers will write the data in the table
5. Here I am using RDBS database. We can have two tables , one is CUSTOMER, RIDE_INFO
CUSTOMER table will contain all the meta data of the customer for eg: cust_id, name, age, address, create_date, last_ride_data
RIDE_INFO will have all the details of ride using cust_id as the foreign key, and other coloumns as CITY, RIDE_TIME, FARE, CUST_ID
In order to optimize the query , we need to partition it by data and then sub-partition it by city
We can also use sharding which can help in horizontal scaling. Sharding should be done based on city, so that all the data for a particular city sits in one server.
6. Now we can create the group by queries on the RIDE_INFO table, assuming 25-SEP-16 is today's date
To get total trips: select count(*), city from RIDE_INFO group by city where ride_time > '25-SEP-16'
To get total fare : select sum(fare), city from RIDE_INFO group by city where ride_time > '25-SEP-16'
To get fare from old clients: select sum(fare), city from RIDE_INFO ri,CUSTOMER c group by city where ride_time > '25-SEP-16' and ri.cust_id = c.cust_id and c.create_date < '25-SEP-16'
To get fare from new clients: select sum(fare), city from RIDE_INFO ri,CUSTOMER c group by city where ride_time > '25-SEP-16' and ri.cust_id = c.cust_id and c.create_date > '25-SEP-16'
7. In order to display in the UI, use MVC model

- techdebugger.zg September 24, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As question says there will be millions of updates so in that case it looks impossible to use DB because DB CRUD time will be more than in memory operation. We can implement in memory solution for this on highly available system with backup. We only interested in total no of trips , total fare, no of trips for new clients and fare collected for new clients.

We can maintain a Set of client IDs so that it will be O(1) operation to identify new or old client. We can maintain a list every day aggregate result in an array. Each element of array will store 1 day result.

class DayResult {
	long totaltrips;
	double totalFareCollected;
	Date day;
	double fareFromNewClients;
	double fareFromOldClients;
}

Class DashBoard{
	Map<String,List<DayResult> results> map=new HashMap<>();
	Set<Integer> clientIds=new HashSet<Integer>();

	public void addTrip(){
		// get trip data from queue or apache kafka 
		String s1 = tripid$clientid$city$datetime
		String s2=tripid$fare

		List<DayResult> results=map.get(cityname);
		int dayIndex=getDayIndex(datetime);
		DayResult  result=results.get(dayIndex);
		Synchronized(Object){
			if(result==null){
				result=new DayResult();
				result.totaltrips=1;
				result.totalFareCollected=fare;
				if(clientIds.contains(clientId)){
					result.fareFromOldClients=fare;
				}else{
					result.fareFromNewClients=fare;
				}
			}else{
				result.totaltrips+=1;
				result.totalFareCollected+=fare;
				if(clientIds.contains(clientId)){
					result.fareFromOldClients=fare;
				}else{
					result.fareFromNewClients=fare;
				}
			}
		}
	}

	DayResult getData(String city, Date date){
		List<DayResult> results = map.get(city);
		int arrayIndex=getIndex(date);
		DayResult dayResult = list.get(arrayIndex);
		result dayResult;
	}
}

- Hitesh June 19, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More