I'm implementing a cloud native microservice application using Ballerina as a part of a university project. I've been trying to figure out how to organize the code in the package, understand what a package is, what a module is, and so on.
What I'm wondering is how to structure the codebase for a microservice application. For example, suppose there are microservices for User and BankAccount. They manage the resources and actions related to themselves.
In term of package/module/file, how can I achieve to have those microservices implemented, so that when I run bal run
, I am able to interact with them?
In Ballerina, it is recommended to represent each microservice as a separate package to enable independent development, testing, and deployment. In order to talk from one package to another, you need to communicate over network. You can use HTTP, gRPC for this.
For a practical example, check out this Ballerina microservices project: https://github.com/ballerina-guides/gcp-microservices-demo.
To understand more about code organization, watching this video may help: https://www.youtube.com/watch?v=8Z-i0VxTvK4. Additionally, the official documentation https://ballerina.io/learn/organize-ballerina-code provides valuable information on organizing Ballerina code.
A package is the right development unit for a microservice. At deployment, the right abstraction is an OS process, container, or a pod depending on where you want run your microservice.