SSH Port Forwarding for local development

Motivation

We have an application with a single frontend and a micro service backend. When we were smaller it was feasible to run everything on our laptops while developing locally. Those days ended. However we were able to make a relatively small change to the local setup to allow developers to work around this issue.

SSH Port Forwarding

ssh -L <local-port>:<remote-host>:<remote-port>
ssh -L 9000:remote.backend.com:9000

The command is simple. Anything for localhost port 9000 should actually go to port 9000  at remote.backend.com

Our frontend is a React Web Application and we use nginx to serve on 80/443.  NGINX also proxy passes routes to the required service ports. It was already setup this way when everything ran locally.

location /some-service {
	proxy_pass http://localhost:9090;
}

In this example http://localhost/some-service gets passed to http://localhost:9000/some-service

By adding the ssh port forwarding this continues to work, but now connecting to any remote backend we choose.

Mixing

Often we want to run a couple of services locally, and everything else remote. This setup supports that. Just skip the port forwarding for that particular service.

However, this will only work in one direction. When making REST call we hit a snag.
- local -> local (fine)
- local -> backend (fine)
- backend -> local (not fine)

In practice this hasn't been a huge issue for us. It can be worked around by making sure that all intermediate nodes are running locally. 2 or 3 hops is the most that I've peronsally had to deal with here.

An alternative to this would to not use REST. Other architecture could bypass this issue – such as Event Based with Pub-Sub communication.