1

One of my projects started as PHP but recently some of the new functionality has been written in JavaScript on Node.js platform.

How do big polyglot projects that use multiple languages to write their server components organize their code?

One of the need arises when doing that is to have models and services written in multiple languages. This leads us to:

/models
  /php
  /js
  /ruby
/lib
  /php
  /js
  /ruby

Alternatively we could put implementations written in different languages into the same folder and only differentiate them by the file extension.

/models
  user.php
  user.js
  role.rb
/lib
  auth.php
  service.js
  anotherService.rb

What are some common patterns to deal with this?

0

1 Answer 1

2

It may be the right time to introduce packages. It seems that the project has become complex enough to separate different functionality into independent packages. So the structure might look like this:

/package-1  # (Ruby)
  /models
    file.rb
  /lib
    some-file.rb
/package-2  # (Node)
  /models
    ...
  /lib
    ...
/package-3  # (Node)
  /models
    ...
  /lib
    ...

Having structure like this opens up the possibility of updating code from each package independently, having clean APIs between them, then maybe even some independent versioning of each. Before you know it, you're gonna run full-blown Microservices architecture :-)

Of course every situation is different, but this pattern is very common for large services.

2
  • Great, thank you for this answer. Follow up questions that I have to this is how would you share common code between services then? Say, package-2 and package-3 have some common models. Mar 15, 2015 at 9:22
  • I've seen it done through symlinks - package A using package B would symlink all package B's files to respective package A's folders. But I'm sure there are other approaches as well, like playing with the search paths (in Python we would put dependency folders from package B in PYTHONPATH of package A). I'd expect each package to live in a separate repository in source control, so that packages can control version of their dependencies, etc. Mar 15, 2015 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.