Amazon Interview Question for SDE-2s


Team: AWS
Country: Dublin
Interview Type: In-Person




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

I don't have too much idea of System Design Question neither I have used Amazon Prime Video. But I will try to answer this question according to my perspective.

First we have to think of the functionalities available in Amazon Prime Video:
1. Account Creation of New User
2. Account of User
3. Saved Videos of User
4. Categories of Videos
(a) TV Shows
(i) Entertainment
(ii) Sports
(iii) News , etc.
(b) Movies
Let's first try to design with only these functionalities.

Storage Scalability:-
Assume there are 100000 videos streaming at a moment in Amazon Prime and we can also assume size of each video on an average be approx. 500MB. So, total size or space required to store these videos in the database is= 100000 x 500MB = 50 TB (taking 1000MB = 1GB).
Now assume you chose a machine which can take store upto 10TB. So, number of system requires = 50/10 = 5 machine requires. And we also have to store the redundant copy of the server so as if in the case of server breakdown the request can have a correct response using other redundant server. So, we will have 2 more redundant server. So, total machine required = 5x3 = 15.

Design Goals:-
Designing of the system will be according to CAP theorem, which tells that we can attain any two functionalities of the three i.e., Consistency, Availability, Partial Tolerance. Which two of the functionality we require ? Availability is the must as for each request there must be a (non-error) response. And we are more in need of partial tolerance rather than consistency, because we don't need each updated response but we need the system must work even after break-down.

Latency:-
We don't want a large latency in our system. As, there may be a large number of request each second. So, we will use Load Balancer to distribute the large number of requests among different servers to ease the burden of single server.

Do we need Sharding?
Yes we need Sharding as each day thousands of new videos are added . So, we need Horizontal Integration to increase the number of server.

What if any machine handling Sharding goes down?
If we only have one machine per shard, then if the machine goes down, all requests to that shard will start hitting the DB and hence there will be elevated latency. As mentioned in the design goals, we would like to reduce high latency cases as much as possible.
If we have a lot of machines, one way to avoid these cases would be to have multiple machines per shard where they maintain exactly the same amount of data. We can use the master-slave technique i.e., there are two copy of server and at any time a single server is active called Master Server and a redundant copy of master server is placed also called slave server which keep itself updated every time and activate itself when master server goes down.

This was all back-end part.

Now see some class hierarchy.
We will have a class called System, Videos, User,

class System
{
	vector<User_Machine> v1;
	vector<Video_Storage> v2;
	public:
		void addmachine(int machine_id)
		{
			User_Machine m;
			m.machine_id = machine_id;
			v1.push_back(m);
		}
		void addstorage(int storage_id)
		{
			Video_Storage s;
			s.storage_id = storage_id;
			v2.push_back(s);
		}
};
class User_Machine
{
	vector<User> v;
	int machine_id;
	size_t machine_size;
	size_t available_size;
	public:
		size_t getsize()
		{
			return machine_size;
		}
		size_t available_size()
		{
			return available_size;
		}
		void add_User(User user)
		{
			v.push_back(user);
		}
};
class Video_Storage
{
	vector<Video> v;
	int storage_id;
	size_t storage_size;
	size_t available storage;
	public:
		size_t getsize()
		{
			return machine_size;
		}
		size_t available_size()
		{
			return available_size;
		}
		void add_Video(Video video)
		{
			v.push_back(video);
		}
};
class User
{
	int User_Id;
	vector<Video> v;
	int machine_id;
	string Information;
	public:
		User(int User_Id, int machine_id)
		{
			this.User_Id = User_Id;
			this.machine_id = machine_id;
		}
		void setInformation(string Info)
		{
			this.Information = info;
		}
		int getId()
		{
			return User_Id;
		}
		int get_machine()
		{
			return machine_id;
		}
		void add_video(Video video)
		{
			v.push_back(video);
		}
		vector<int> get_all_videos()
		{
			vector<int> ids;
			for(int i=0; i<v.size(); i++)
			{
				ids.push_back(v[i].video_id);
			}
			return ids;
		}
		Video get_video(int machine_id, int Id)
		{
			for(int i=0; i<v.size(); i++)
			{
				if(v[i].video_id == Id)
					return v[i];
			}
		}
};

class Video
{
	int video_id;
	int video_length;
	size_t video_size;
	int storage_id;
	int video_type;              	// Ids only like 0 for movies, 1 for TV Shows, etc
	public:
		Video(int video_id, int storage_id, size_t size, int len, int video_type)
		{
			this.video_id = video_id;
			this.video_length = len;
			this.video_size = size;
			this.storage_id = storage_id;
			this.video_type = video_type;
		}
		int getId()
		{
			return video_Id;
		}
		int get_storage()
		{
			return storage_id;
		}
};

There are many more things that can be done. As if you are implementing the complete design of Amazon Prime it is not done in less time. It will take a large time.

Here I have just explained few functionalities that can be done in this way. It's just a try all suggestions are welcomed.

- superrishabh0 August 10, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Geiei

- Anonymous July 07, 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