Can I provide callback from frontend (react) to backend and create API endpoint in react?

I develop service which will use ML for create response. So we can wait for response for about several seconds. So it’s quite long time and I need not to block my frontend while waiting for response.

I develop my ped project and I’m newer in programming, so facing with such problem (wait for long response) for the first time. So how can I build architecture in my project, to solve this task?

One way I’ve found that I can send from frontend my request (it’ll be simple string) and with this I’ll send unique API endpoint (generate it with userId and queryId: http/…/query/{userId}/{queryId}) and the create endpoint with this url in frontend.
When response will be prepared my ApiGateway will send it to provided endpoint. So as a result, it turns out that the backend will send a ready response to the frontend, and this api will listen to the frontend.

I came to this approach, beacuse I have ApiGateway on the server and as I understood, I shouldn’t block this ApiGateway by opening websocket connection or something like this. Because when some client open connection with server another client won’t be able to connect to server.

As a result, I have the problem that I have a server that inherently (due to working with ML) will take a long time to process requests. At the same time, I need to somehow think about the moment when sending a request from the client (frontend) so that the client, while waiting for its long response, frees up the ability to connect to the server of other clients

I do programming unprofessionally and do not work anywhere, but now I’m just working on my project. Therefore, perhaps my question may sound stupid, but I hope that someone can help me, I’ll be grateful for any help

My current architecture looks like here:

  1. client (frontend on react) send request to backend (ApiGateway – Asp Net minimal API)
  2. ApiGateway check the query and then send it through kafka to ML
  3. One of services get the response from ML, handle it and send to ApiGateway through kafka
  4. ApiGateway needs to send this response to client — how to do that? – or maybe I need to restructure my logic?

So as you see ApiGateway just forwards requests, and so in theory can handle requests from multiple clients

The “correct” way to do this from a HTTP standpoint is to return a HTTP 102 response from the endpoint until the ML processing is complete and the response delivered to that endpoint. Websockets obviously could “solve” this, at the cost of a higher connectivity requirement.

  1. Client requests through API gateway
  2. API Gateway provisions an endpoint url and sends the request through kafka (passing in the endpoint so it knows how to retrieve the payload)
  3. API Gateway returns a “Continue” message to client (202) with the URL for the endpoint
    3.1 Client begins polling endpoint, receiving a HTTP 102 response until it’s complete
  4. Service gets response from ML, fulfills the endpoint (this will require some kind of storage, probably a cache like Redis or similar)
  5. API Gateway (or backing service) returns the fulfilled response and sends it when the client next polls

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật