Why Cellery is code-first?
Cellery is a code-first approach to building, integrating, running and managing composite applications on Kubernetes. Build, push/pull, test, deploy, update, scale and observe cells. Cellery lets using your existing container images, written in any language.
This article explains why a code-based approach is selected in Cellery to create composites.
In the modern programming world, there have been two ways to handle integration.
- Config-based
- Code-based
Cellery approach to creating composites using code, not configurations.
As developers, we are used to editing, build, run, test cycle. And it is not appealing to write configurations in huge YAML/XML/JSON files in an IDE where you don’t have a type checking, code completion and other cool stuff.
For an instance consider the following cell.
In the above Cell, there are five components. Namely,
- Orders
- Customers
- Catalog
- Controller
- Gateway
Generated YAML configurations for the above cell will look like below.
The yaml file is 125 lines long :) It will be time-consuming and error-prone handcrafting this YAML file.
In most cases, we copy a yaml file and edit rather than writing from scratch. Few problems with the above approach are as follows.
1. No type validation until runtime: Imagine setting a string where an integer is expected. The error will be only caught at runtime when deployed.
2. Lack of IDE support: The IDE or tooling support is limited when writing a custom yaml. Documentation should be referred to in order to identify supported fields and value types.
3. Error-prone: One mismatched space can ruin the whole yaml. :)
4. Not Extensible: Dynamically changing the values of the YAML are not possible. Ex: Read the threshold value from an environment variable.
Now let’s look at the corresponding cellery code. The syntax of Cell File is Ballerina but knowledge of the Ballerina programming language is not necessary to make modifications to the Cell file since it is mostly simple variable assignment and method invocation.
In the code-based approach, we only have 100 lines including comments and newlines. Following are the advantages that on code first approach.
- Type Checking at Compile Time: The cell file is compiled before deploying to the cluster. The compiler ensures the cell is type-safe and grammatically correct. This means no waiting till runtime to detect errors.
2. Tooling support: Tooling support is there with IDE plugins. Code completion, Type validation, and syntax highlighting are provided.
3. Extensible: The code can be written in an extensible way. All the packages, constructs, connectors from Ballerina language can be used inside the cell file.
The following code fragment shows how to set the value for the controller component’s scaling policy at the runtime.
4. Debug Support: The code can be debugged and tests can be integrated as we are doing for any program written in a programming language.
Conclusion
Config based approach is suitable for small composites. But with a code-based approach, it is much easier to create composites.
Explore Cellery with samples: