Server configuration for REST API and web client

I have developed a REST API with go (golang) and now I want to create my web interface. I don't know how I can decouple the frontend from the backend.

I think I have three options:

1- Run REST API on one server and frontend web site on another server.

2- Run REST API and frontend website on the same server but on different ports. For example, run REST on port 8080 and frontend website on port 80.

3- Run Both on the same server and on the same port, but different URL paths (or subdomains) are used for each.

As I don't know about this, please tell me which one is the true or best solution. Or is there another solution? Does it matter how big my site is?

+3


source to share


1 answer


Either the first or second option will be basically the same for you to customize and develop. So you don't lose or gain anything from this point of view, the only deciding factor is your resources and how you expect your backend to be used in the future.

Currently, if you only have one application / external API call, if they are on the same server, this would be the best option as it will have slightly improved performance compared to the second option.

But since you've chosen a RESTful project for your backend, you can reuse it for more applications in the future, and if you expect more calls to the API to start using server resources, then your frontend may suffer from it and you should think about moving the backend to another server.



All microservices, "RESTful" backend "pattern" were created to separate the front and back for better scaling, but this may not be necessary for everyone, you should estimate the volume of application usage, which will be realistic, and think if you can actually actually reuse the API elsewhere (or if you want to offer the API to others or not).

In the end, if the first and second options represent the same amount of investment for you at the moment, go for the first one, if not, just keep the front and back on the same server, and if in the future you are what you need to scale, you you can just move the API to another server / server.

+1


source







All Articles