Answer the question
In order to leave comments, you need to log in
How to build and deploy Go applications?
Hey!
Started on the path of learning Go, came up with an ambitious project for this and ran into this. that I am tormented by several questions, without knowing which it doesn’t really start:
1. The project must have both a web server and scheduled tasks. This, of course, uses common code, such as ORM objects. Is it okay to have a separate rooted application for console tasks (or even 100500 applications for each task)?
2. Knowing that the entire project will be built on Go, does it still make sense in queue managers and isn't it easier to run the corresponding tasks in gorutins?
3. How to properly deploy an application with a web server so that the user does not notice version switching?
For now, I think it's right to run each new version on its own port and switch the nginx user flow to the appropriate port. Is that normal, is that what they do? Run the server itself in screen?
Thanks for the replies!
Answer the question
In order to leave comments, you need to log in
1. It will be normal to run both inside a single process (using some kind of robfig/cron , for example), and separate processes (cron tasks, or even daemons). It all depends on the specific situation and what you need. Each approach has its obvious trade offs. Just choose what suits you best. This has little effect on the codebase, because you can always reuse packages, and in general you can keep everything in a single binary by simply throwing in different CLI interfaces.
2. Goroutines cannot be shared between multiple servers. If your ambitions fit into one server, then you can not load on external queues.
3. If we are talking strictly about one process that cannot be propagated, then look towards graceful updates / restarts. If you can multiply the application (after all, we live in the age of the victorious Docker / Kubernetes), then there are more general techniques that are suitable for absolutely any application: blue / green deployment or rolling update (in the same Kubernetes out of the box).
I wouldn't use internal queues.
External queues will not lose data when the application crashes.
I don’t know about the construction, but I’ll tell you a little about the deployment, it will suddenly be useful. Here is an article on Habré: https://m.habr.com/ru/post/421087/
At one time I was tormented to look for how this is done correctly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question