absmach / magistrala

Industrial IoT Messaging and Device Management Platform
https://www.abstractmachines.fr/magistrala.html
Apache License 2.0
2.48k stars 673 forks source link

Explore API Gateway options #1958

Open dborovcanin opened 10 months ago

dborovcanin commented 10 months ago

With the recent changes in architecture caused by Auth service and SpiceDB, there is a need for API aggregation. A simple example is Domain removal in Auth svc, which should result in all the Things and Groups (and Users) being removed (from the domain). This causes messy and circular dependencies between Auth and other services. Extracting API aggregation and authorization to API GW would solve this problem. It would also simplify domain services. One more benefit is that it would remove the need for private API because internally, we can have all the data we need (say, when we need an email for users), and API GW will take care that those data are not leaking to the end-user.

arvindh123 commented 10 months ago

Possibilities usage of API Gateway in Magistrala

API Gateway Advantages :

Alternative for API Gateway Retrieve Basic data

arvindh123 commented 10 months ago

Domain Delete

Domain Delete Process required of following

Current Delete API Endpoints in other entities:

At present we have HTTP API endpoints for deleting in other entities are:

Standard Approach for delete domain using existing API

On receive of delete domain request following steps will taken by the Delete function in Domain Service

Advantages :

Disadvantages:

API Gateway using existing API

API Gateway act as intermediate proxy for domain delete request Once the domain delete is received in API gateway, it does the following steps :

Advantages:

Disadvantages:

Scheduler JOB to clean

In this approach , Delete Domain function in Domain service will just change the state of the domain to delete Scheduler will look for the list of Domains with Delete status in Database And picks the list of domains to delete and run individual jobs for each Domains

In Steps:

Advantage:

dborovcanin commented 10 months ago

@arvindh123 Thanks for the report. I have a couple of questions:

  1. What are the general disadvantages of the API gateway approach?
  2. Does it make sense to update Things so that each Thing has its domain? Will that simplify Domain removal?
arvindh123 commented 10 months ago

Disadvantages of API Gateway:

My View : We have most of functionalities are working condition except delete flow.

If we have API Gateway, Delete process will take time, if there are 1000 of entities to delete, So API becomes slower and irresponsive

So for now, we can proceed with building gRPC endpoint for removal of Things, channels and groups And , Delete the domain with cleanup job.

Later over time, we can add other gRPC endpoints and after that we can start building API Gateway for other API aggregations For now time being, we can do aggregation in UI Service. I believe, UI service is already doing API Gateway kind of aggregation work.

arvindh123 commented 10 months ago

2 Does it make sense to update Things so that each Thing has its domain? Will that simplify Domain removal?

Adding domain to entities will help partially (50%) in domain delete process. We can have a separate function in each entities repo to delete all entities related to one domain. But for Policy removal we need to send individual request to remove policy . Remove policy works like matching of Subject Object and Relation. This can be done faster, by sending parallel batch delete request to spiceDB.

As I said in previous answer having cleanup job will simply domain delete process for now and API Gateway might not be a right choice for Delete flow as explained in previous comment

dborovcanin commented 9 months ago

This one might also be addressed by API GW: https://github.com/absmach/magistrala-old/pull/269.

dborovcanin commented 6 months ago

Relevant document: https://docs.google.com/document/d/1tJ78iHx-_-W-GO5YFa8T1yd65Hu-AsxLmSDpwg5mBYw/edit#heading=h.nc9o9iq9wvl6.

arvindh123 commented 5 months ago

List of API Gateway

Golang based API Gateway (Random order)

OpenResty based API Gateway

Note: We can build our own API Gateway according to our need with https://openresty.org/en/

Java

dborovcanin commented 2 months ago

This may be a part of https://www.github.com/absmach/mgate.