Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 630967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:54:48+00:00 2026-05-13T19:54:48+00:00

I have a design question for a multi-threaded windows service that processes messages from

  • 0

I have a design question for a multi-threaded windows service that processes messages from multiple clients.
The rules are

  • Each message is to process something for an entity (with a unique id) and can be different i.e DoA, DoB, DoC etc. Entity id is in the payload of the message.
  • The processing may take some time (up to few seconds).
  • Messages must be processed in the order they arrive for each entity (with same id).
  • Messages can however be processed for another entity concurrently (i.e as long as they are not the same entity id)
  • The no of concurrent processing is configurable (generally 8)
  • Messages can not be lost. If there is an error in processing a message then that message and all other messages for the same entity must be stored for future processing manually.
  • The messages arrive in a transactional MSMQ queue.

How would you design the service. I have a working solution but would like to know how others would tackle this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:54:48+00:00Added an answer on May 13, 2026 at 7:54 pm

    My approach would be the following:

    1. Create a threadpool with your configurable number of threads.
    2. Keep map of entity ids and associate each id with a queue of messages.
    3. When you receive a message place it in the queue of the corresponding entity id.
    4. Each thread will only look at the entity id dedicated to it (e.g. make a class that is initialized as such Service(EntityID id)).
    5. Let the thread only process messages from the queue of its dedicated entity id.
    6. Once all the messages are processed for the given entity id remove the id from the map and exit the loop of the thread.
    7. If there is room in the threadpool, then add a new thread to deal with the next available entity id.

    You’ll have to manage the messages that can’t be processed at the time, including the situations where the message processing fails. Create a backlog of messages, etc.

    If you have access to a concurrent map (a lock-free/wait-free map), then you can have multiple readers and writers to the map without the need of locking or waiting. If you can’t get a concurrent map, then all the contingency will be on the map: whenever you add messages to a queue in the map or you add new entity id’s you have to lock it. The best thing to do is wrap the map in a structure that offers methods for reading and writing with appropriate locking.

    I don’t think you will see any significant performance impact from locking, but if you do start seeing one I would suggest that you create your own lock-free hash map: http://www.azulsystems.com/events/javaone_2007/2007_LockFreeHash.pdf

    Implementing this system will not be a rudimentary task, so take my comments as a general guideline… it’s up to the engineer to implement the ideas that apply.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.