Computer Science Interview Proficiency

Posted

From time to time, I’m in charge of interviewing potential candidates applying for a Computer Science / related job…

Asking basic algorithm questions can sometimes be boring.

Sure, you can prove to me that you know how to invert a binary tree; but you could have rote-learned it prior to the interview. Whilst these sorts of questions are somewhat good (they assess your academic understanding), chances are that you won’t ever be using it in your actual job (my condolences to those who have graduated with a CS degree, to then land a job role as WordPress site developer).

More often than not, in a company you won’t be dealing with the entire full-stack of application development; You’ll be assigned to a specific part of the development - frontend, backend, dev o(o)ps, etc. But of course, a recruiter would prefer the best candidate - someone who can do everything - and that’s why we ask the ‘basic CS interview questions’


Of course though, after the first stage(s) of recruitment are over (i.e. the resume/CV stage, and the mass-scale programming exercise), we get to the fun technical questions - where as an interviewer I get to write fun questions!

I thought to put them here for the benefit of anyone wanting to prepare for a technical interview. Whilst these questions go beyond the scope of what my company is looking for, being able to answer them (or even an attempt to) demonstrates their deeper understanding of computer systems - and helps me find the keen beans who are personally invested in their CS journey, apart from just university knowledge.


Networking

A company has two HTTP (non-secure) web servers (written in any arbitrary language) that they wish to host on a single server computer, accessible via the internet. The computer is directly exposed to the internet, and thus has a IPv4 WAN / public address 111.222.333.444. The company wishes to access their servers through their domain name company.xyz, or some subdomain thereof. They also desire a secure web connection to these two servers whilst also using the default web ports.

Propose a technical solution that can cater to the company’s needs.

This question assess several core networking fundamental: DNS, socket/port binding, routing and SSL.

As with all things computing, there are many different solutions to the problem - generally it will involve some sort of reverse proxy. Before I propose an example solution, let’s take a look at what’s being assessed from this question.

DNS
As a key requirement to the problem, the websites being served must be accessible from some domain name (http(s)://company.xyz), rather than directly through their IP (http(s)://111.222.333.444). In turn, this requires the interview candidate to explain about A (or AAAA for IPv6) records, in order to set up a (sub)domain that points to the IP.

Port Binding
At the bare minimum, you can easily host two web servers on the same machine if they are bound to separate ports (i.e. port 80 and port 8000). Therefore with an A record company.xyz -> 111.222.333.444 set up, we would be able to access the servers via http://company.xyz (port 80 is used by default) and http://company.xyz:8000. However as the scenario dictates, both web servers must be served from port 80 (or 443 for a HTTPS connection). In order to do so, we will need some sort of middleware that can listen to port 80/443 and redirect traffic to the correct web server

Routing
This is where I would hopefully hear the key phrase “reverse proxy” - which is a term to describe a software router (or appliance) that directs requests to their required destinations. A reverse HTTP(s) proxy would listen to a website request, and handle that request by forwarding it to the desired web server. Doing so will address the scenario requirement for both servers to be served from the same web port - The reverse proxy will listen on port 80/443, and then redirect the request to whichever of the two servers is required.

Of course, the laws of port binding still hold - the reverse proxy and the two web servers can’t share the same port of the same IP address. This is however acceptable - the two web servers can be on any arbitrary port (and preferably bound to localhost / 127.0.0.1, with the reverse proxy listening on port 80/443. Therefore to the end user, all that they are exposed to is port 80/443.

A reverse HTTP(s) proxy is able to route requests by either hostname (http://a.company.xyz and http://b.company.xyz), or by directory (http://company.xyz/a and http://company.xyz/b) - therefore satisfying the requirement for both web servers to use the default web ports.

Seems like a lot of work for something trivial right..?
Well reverse HTTP(s) proxies offer more benefits!

SSL / HTTPS
In order to turn your HTTP web server into a HTTPS one, you will need to modify your code / the server to add in the SSL functionality. You also need to manage providing the SSL certificates to the service. In addition, not all programming languages (and hence their server code libraries) are created equally - some are slower than others! It’s for these reasons (portability and speed) that we turn to reverse HTTP(s) proxies!

Reverse HTTP(s) proxies are often written in performant languages, like C, C++, Go, etc… as they can handle the HTTPS functions faster than what might be done in Node.js or Python (for example). They also allow you to centralise and simplify your HTTP/HTTPS configurations between different servers.
As in the name, these proxies can proxy your HTTP-only web server (i.e. the ones in the scenario) through a HTTPS connection; essentially meaning that you will now be able to visit your website securely!


So an example solution to this scenario would be to have a reverse HTTP(S) proxy that routes requests internally to the two HTTP web servers.

To access the first server, a user can navigate to https://server1.company.xyz
To access the second server, a user can navigate to https://server2.company.xyz

Here, the reverse proxy will listen on port 443 (bound publicly), and the two web servers will listen on ports 8001 and 8002 (both bound locally). When the user visits either (sub)domain name, the DNS records will point them to the server’s IP address where the reverse proxy is waiting to direct the request to the correct server.

DNS A Record: server1.company.xyz -> 111.222.333.444
DNS A Record: server2.company.xyz -> 111.222.333.444
Reverse Proxy (HTTP, HTTPS) - Listening on 0.0.0.0:80 and 0.0.0.0:443
Route requests from server1.company.xyz to 127.0.0.1:8001
Route requests from server2.company.xyz to 127.0.0.1:8002
Web Server 1 (HTTP) - Listening on 127.0.0.1:8001
Web Server 2 (HTTP) - Listening on 127.0.0.1:8002
(And for brownie points) Upgrade HTTP requests to HTTPS requests

For the reverse proxy, we could use Nginx, Squid, Apache or Caddy (just to name a few).
Perhaps some sort of interaction with Docker / Kubernetes could be used too!

As another added bonus, by binding the two HTTP web servers (insecure!!!) to a local-only address, no external entity will be able to visit the servers via HTTP - the only way to access the web server is via the web proxy through HTTPS! (Let’s hope there’s no SSRF vulnerabilities in your infrastructure).


This scenario is especially good for those who are looking into a networking dev-ops role.
It’s actually quite a common scenario that any programmer should really know how to do - as it’s close to the basics of server hosting and network application security.

Also fun trivia, on Linux only root can bind port numbers that are lower than 1000!

JavaScript (and JS Frameworks)

These questions are laid out more as general “explain this concept” questions, than a full-fledged scenario

More posts

NDI Streamer

Making a clone of the NDI Scan Converter application

Posted

UNSW SENG4920

Management and Ethics

Posted