[Architecture] Moving app logic to server side

Alessandro71

Well-Known Member
Licensed User
Longtime User
Not quite a "Chit Chat" topic, but I've found no proper place for an architectural topic, on which I would like to hear views and experiences from other developers.

For various reasons I won't go into details here, I'm going to evaluate the option of moving my app core logic to server side, and making the app as lean as possible, just like a "thin client".
Since on the app side I have to deal with external devices connections, it can't be a fully web app, since I need some code and logic on the phone, to deal with connections management.
Since the app is obviously written in B4X, porting to B4J the server component should be easy.

I see an issue with the fact that, right now, the code works in a "single user/single instance" mode:
The app logic, running on the phone, works for a single user: porting it to server side, must deal with multiple users using it at once.

I see an "easy path" and a "right path":
  • "easy path": leave the code as-is (single user/single instance) and let something external deal with: when a user starts the app, a new server instance is created and bound to that app session.
  • "right path": rewrite the core code logic to deal with multiple sessions/multiple users at once, so the app will always connect to the same server instance.
the "easy path" resembles the way docker containers scales out for handling traffic increase behind a load balancer: is there anything similar for B4J server apps?
the "right path" has a deep impact on the code, with a massive rewrite involved.
 

hatzisn

Expert
Licensed User
Longtime User
I always wanted to learn Kubernetes and I am not totally sure if it can create new instances of vps but If I remember correctly from some videos I have watched in the past, this might be the case.

According to this tutorial, this is not the case but you can use a Cloud Provider specific API to create/destroy nodes for the Kubernetes or just use Terraform which does this according to ChatGPT :


For containers though, it is a sure thing that Kubernetes does it and if you look at docker hub you can find an image with latest OpenJDK and use it to create a container with B4J utilizing an appropriate dockerfile. For an example creating a docker image with a B4J jar file and the corresponding www + logs check the B4J tutorials in my signature in my contributions. This is if you choose the server way.

To be honest I believe the transferring of an app to a server should be done only if there are issues of hiding something from the end user (f.e. an API Key or user validation/access granding or a specific procedure or something like this).

If you use the server way make sure you will avoid concurrent record manipulation.


And a free candy from ChatGPT (the question is: "Can Kubernetes and Terraform cooperate?") :

Yes, Kubernetes and Terraform can definitely cooperate, and they often do in modern cloud-native environments. Here’s how they can work together:

1. **Infrastructure Provisioning**: Terraform is primarily used for provisioning and managing infrastructure resources (like VMs, networks, and storage) in a declarative manner. You can use Terraform to set up the cloud resources needed for your Kubernetes cluster, whether it's a managed service like GKE, EKS, or AKS, or a self-hosted cluster on virtual machines.

2. **Kubernetes Resource Management**: Once your Kubernetes cluster is running, you can use Terraform with the Kubernetes provider to manage Kubernetes resources such as Deployments, Services, ConfigMaps, and more. This allows you to keep your infrastructure and application deployment in a single codebase.

3. **State Management**: Terraform maintains a state file that keeps track of the resources it manages. This can be helpful in understanding the current state of your infrastructure and Kubernetes resources, making it easier to manage updates or changes.

4. **Modular Infrastructure**: You can create Terraform modules for your Kubernetes setup, allowing for reusable and consistent deployments across different environments (e.g., dev, staging, production).

5. **Integration with CI/CD**: By integrating Terraform and Kubernetes in your CI/CD pipeline, you can automate the deployment of infrastructure and applications, ensuring a smooth and consistent workflow.

In summary, while Kubernetes focuses on container orchestration, Terraform handles the provisioning and management of the underlying infrastructure, making them a powerful combination for managing cloud-native applications.
 
Last edited:

b4x-de

Active Member
Licensed User
Longtime User
Architecture is a difficult topic. I used a Model-View-Presenter (MVP) pattern in conjunction with the Data-Access-Object (DAO) pattern for a clean layering. I separated each in their own b4xlib, i.e. a lib for models, a lib for views, a lib for presenters. For Android and iOS I created native projects that use these libraries in their Activities and Pages. That separates the platform specific logic. For the Web app I use the B4j server and call the presenters from the Handlers. Model and DAO is the same. I only needed a new View based on Thymeleaf. You might check the API Server that is available here in the forum instead. Hope this helps.
Thomas
 
Top