API interaction sequence
We know there is a need for RESTful APIs to receive images from the client. Then, the client should be able to indicate in the microservice through the APIs to generate the model and save it for subsequent download and rendering.
Here is where a web framework comes into play. For this task, we chose Vapor.
Vapor Web Framework
Vapor is the lightweight web framework of choice. It enables faster development of web applications with RESTful APIs and can be deployed on Docker and Linux machines. However, we required MacOS-specific API because of RealityKit and that eliminated both Docker and Linux as options.
As for the Kitura web framework, we did not go with that as its development has not been very active.
On the other hand, Vapor is still undergoing active development and receiving support from its developers. Furthermore, we have the requirement to build a multi-architecture application. Another advantage is that Vapor is built for both x86-64 and arm64 architecture on any macOS.
The importance of concurrency
The model generation process requires a significant amount of CPU and GPU power to create the AR model, taking several minutes on an Apple Silicon such as the M1 SoC or even more when running on Intel processors. This impacts the overall performance and response time of the system. As a result, the operation cannot happen on the same thread as the RESTful API that receives the images or the main server event loop.
So, what we can do?
Use concurrency and async processing.
The AR model generation must be a parallel task triggered by the API or other mechanism such as a timer job. This allows the APIs (such as the image upload API) to behave in a fire-and-forget manner.
However, this comes with challenges.
With parallel processing, the client cannot receive the current processing status updates via the API. Instead, what we can do is display the progress percentage of the activities via notification. Our solution involves implementing a notification system, as shown in the diagram below.