Need more documentation about the spawning of new instances for different kinds of classes

Rails has documentation that states that a new instance of a Controller is created for every request. What seems to be lacking in the documentation is how Rails decides to spawn other types of classes.

With the rising popularity (I think?) of Rails developers utilizing POROs and implementing a Service layer, it seems important to give some pointers on how those classes are initialized.

This depends on a bunch of things, like multi-threaded or multi-process app server, and how the app server might re-spawn processes in the case of multi-process, but I do think it’s Rails responsibility to provide some helpful tips for things to think about.

For example, a lot of developers use class-level methods for their Service layer, and they don’t create an instance of that Service. It would be a helpful tip to let them know that when doing so, if they use class-level variables, they’re going to see data-sharing issues across requests, since that Service class lives for more than one request.

A post was merged into an existing topic: An extensive example of project organization