Facebook Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Dang it ... I meant to write:
Design a Tiny URL system.

- JSDUDE January 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The simple answer is hash =)

- Sergey January 20, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Hash table with an interface to code/decode the hash values as "browser-friendly" ASCII strings. Base64 or Base56 are good choices for this.

Speed can be improved by using caching. The most visited URLs and their hashes would be maintained in a caching hash table that is kept in main memory.

- Victor January 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

No its not a hash. Read on stackoverflow how people acheive the tiny url by simply using base 62 numbers and autoincrement id in a database. Rest is just scaling the system.

- xmlprgrm June 21, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Questions
How tiny?
If a URL is already shortened, do we shorten it again?
If a URL is a URL that does not lead anywhere, but is a made up URL, then do we still shorten it?
If the URL is already “short enough” do we shorten it further?
Do we shorten URLs that are short URLs generated by our short url system?
How many URLs are we talking about? -- Is it more than Long.MAX_VALUE?

Core Design
Insert URL to database and use something like base 62 [a-z,A-Z,0-9] encoding of the index column.
We look up if a URL is already shortened -- if it is then return that shortened version.
Go to URL and don’t create a short URL if you get a 404 or if DNS resolution fails (domain doesn’t even exist)
Check for malicious content.
Check against a blacklist of websites.
Send content to an API that tries to use AI to understand if malicious content.
When a user does a GET on a short URL, then do a 302 to redirect user to it.
Provide functionality to flag a URL.
Provide functionality to delete a URL?
There can be a potential problem here - If I insert a URL, delete it and then repeat this process a large number of times, I will extinguish available short URLs
Provide functionality to detect DOS attacks
Throttle number of requests per IP per URL.
Add frequently used URLs to cache.
Disk/Database -
--Replication
--Sharding - based on URL
--Disk striping (RAID0)
--Use SSD.

Cache
Distributed cache
Edge cache servers for regions.

Possible problems
If I insert a URL, delete it and then repeat this process a large number of times, I will extinguish available short URLs
-We can mark a URL deleted on delete, then while creating new URLs, first get the list of URLs marked deleted and replace the first one of those
-If no URL marked for delete, then insert new record into DB.

- bp February 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what will it be used for?

- Henrywang0113 January 16, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Would you please share more details?

- Marcello Ghali January 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We need to know what exactly a "URL system" mean. Designing a class or interface such as URL(String protocol, String host, int port, String file)? or designing a file system which takes URL format?

- anderson January 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Could you post your code, please?

- Maksim January 23, 2015 | 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