Facebook Interview Question for SDE-3s

Country: United States
Interview Type: In-Person

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

I would ask the interviewer a few questions:
1. If a server is already processing a message, can we assign it one more? (i.e. is the server capable of queuing up messages or processing them in parallel?)
2. If No, is it OK to assign fewer messages to a slow server?

I would start with a simple round robin solution like this and improve on that based on the answers to the above:

package com.test;

public class RoundRobinDistribution {
    public static void main(String[] args) {
        String[] servers = new String[] { "S1", "S2", "S3"};
        Distributor distributor = new Distributor(servers);
        for(int i=0; i < 5; i++)
            System.out.println("Message " + i + " to " + distributor.getNextServer());

    private static class Distributor {
        private String[] servers;
        private int index = -1;

        Distributor(String[] servers) {
            if (servers == null || servers.length == 0)
                throw new IllegalArgumentException("Servers list is empty");
            this.servers = servers;

        public String getNextServer() {
            index = (index + 1) % servers.length;
            return servers[index];

- kredible May 21, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Hash = MessageID % N (mod N)

- TM May 21, 2017 | Flag Reply

Add a Comment

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


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


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