Background thread processing vs queue based processing for relatively short tasks (max 30-40 seconds)

I need suggestion / recommendation on the design approaches mentioned below.

UseCase: I have a usecase where a client uses my system to generate some recommendations. Now, these recommendations are generated in 2 phases. In the first phase, client sends some payload and I make a DB call and a service call to generate an intermediate recommendation. This process takes around 30-40 seconds. In the second phase, cliend sends some additional data and I filter the intermediate recommendations with that additional data. In the second phase I make a DB call and a smaller LLM model (so the average latency would be 3-5 seconds. Following are my questions.

For the first phase, there are three approaches.

  1. I ask the client to push a message to FIFO Queue, and a poller within my service polls the message.
  2. I could be to create a standard API, accept the request and start the task execution on a separate thread.
  3. The third approach is same as above, just that instead of processing in background pushing a message to a queue, and a consumer will poll for messages.

3rd one is ruled out as it doesn’t offer much value and I will always have 1 client, Amongst 1 and 2, I am more aligned on #2, because using a queue looks like an overkill here. Does anyone have any thoughts on this?

For the second phase, there are 2 approaches

  1. Implementing a blocking API where I wait for the smaller model call to complete.
  2. Implement a status message based API where on first call I accept and process the smaller llm call on a separate thread, and then let the client poll and i could return with either in-progress or success call.

I am preferring approach 1 here, since it keeps things simple (as the max latency I would want for this API would be 2-3 seconds). However, the downside is that the system resources would be held (threads). Does anyone have any thoughts on this?

3

The deciding factor for me between a queue based response and a thread based response would be:

  • The volume of concurrent requests that are needed to be serviced
  • How the API is hosted.
  • The fault tolerance required around a duplicate and/or failed request.

If you are thinking that you will have more concurrent requests than hyper threads available on your server’s CPU’s then you should start to think about queuing requests.

Wanting fault tolerance also points towards queuing as a strategy.

Hosting the API in the cloud may mean that you have automatic scaling of threading capacity (AWS Lambda) but you still have to think about the database performance. Hitting it with too many simultaneous requests will hurt its performance badly.

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