Amazon Interview Question for SDE-2s


Team: Transportation Team
Country: India
Interview Type: In-Person




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

I think the interviewer was expecting a lot of questions to clarify. Sometimes, they keep the questions vague intentionally. I am only going to consider the information provided here by OP and post my thoughts.

Requirements:
-> Send 100 Million emails (don't know the time frame, but assuming 1 day for now)
-> 5 machines to send emails. Client machine who sends the email is not included here
-> All machines are of same processing power

Let's go top down:

-> 100 Million emails can be divided into 5 machines, not necessary uniform, but approximately it would translate to 20 M per machine
-> 20 M / 24 hours means 231 emails per sec
-> This means that there are 231 QPS required approximately for a single machine on an average

Email Service:
-> A service that would accept messages via open socket connection
-> Validates the message before sending it asynchronously
-> Sends response back to caller/client with success failure. In case of failure, it sends appropriate Error messages
-> Has retry mechanism for certain types of errors (e.g. network error)
-> Uses message queuing system like Rabbit MQ to send messages (RabbitMQ can convert SMTP messages to AMQP) to send emails
-> You don't need this really since you are using Rabbit MQ, but can implement throttling using token bucket algorithm

Email Client Lib:
1. Validates the email content before sending it to Email Service (e.g. maximum size of attachment, parameters of the email, etc.)
2. Compresses the message before sending to reduce network traffic
3. Retry logic in certain failure scenarios (e.g. in case email sever is busy, it can back off before retrying)

Client API can include following steps:
1. Setting SMTP Client : SetUpEmail(host, port, enableSSL, deliveryMethod, credentials)
2. Setting up Email: CreateEmail(sourceEmail, destEmail, subject, body, attachment)

Email Service APIs can be created in a similar way. I guess the idea here is to design than code.

As of security, SMTP requires credentials. We are also compressing the packet while sending it on network and using SSL to send email. Should be pretty safe. You can add encryption from client to server in addition to compression, if your email includes unicode characters.

We can discuss about the challenges of this design:
1. Availability: One of the machines might go down affecting the performance
2. Scalability: You can add more machines to make it scalable, but then you would have to update your design accordingly.

- animageofmine June 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you clarify your question?
What are those 5 machines capable of? Can they send emails simultaneously?
Are the machines having equal processing power?

- puneet.sohi June 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes they can send emails simultaneously and machines having equal processing power.

- shaileshagarwal1 June 15, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

this looks like a job for message queues (AMQP protocol, take your pick RabbitMQ, ZeroMQ, etc...)

- Anonymous June 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

how about a simple token bucket algorithm? get the token, use the machine. use a queue to store all pending jobs.

- addy June 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ada d adad

- Anonymous November 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
- Anonymous November 02, 2017 | 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