locked
Is there a Push model implementation using the basic .NET classes ? RRS feed

  • Question

  • While developing an application for a bus reservation system, I ran into this situation ….

    I have a Bus of 50 seats and there are some 1000 users who are online trying to book seats for a particular trip. Let’s assume that one of the 1000 users (say user 108) made a booking for Seat no.32 by calling BookSeat(Int32 SeatID) from the library function.

    How will I update the screens of the other 999 users, instantaneously, with the current seating configuration (indicating that the seat no 32 is booked).

    Possible Solutions:

    1. Polling mechanism (Pull model): For a customized interval, check the status of the List<Seat> and then refresh the same across the UI. If there is a change, the change will automatically be reflected. Disadvantage: This is a pull model and adds an overhead to the application performance.
    2. ASP.NET SignalR – I guess I can find the answer to this problem if I go a bit deep into Signal R, but I wished I could address this in the Class/ object/ pattern level instead of relying on a supporting tool like Signal R.

    Is there a “push model” for this scenario?

    i.e. when a seat is booked through one of the active sessions, send a message to the other 999 connected sessions with the List<Seat> data. A call back function (delegate) will probably update the UI. Observer pattern is also in my mind but am not able to put the pieces together!  Any help in the forum please! :)

    Wednesday, February 3, 2016 7:09 AM

Answers

  • SignalR is meant for the type of requirement you have and its .NET. SignalR will push the updates out to your clients. If your client application supports web-sockets, even better. You can also scale with SignalR as well.

    If your client isn't web-based, then sure you could probably implement something yourself using the Observer Pattern.


    william xifaras

    Tuesday, March 22, 2016 4:48 PM
  • I'm not sure a long-poll technology such as SignalR is really the solution here. This is a classic airline booking problem that has been around a very long time. I'm not saying SignalR wouldn't help but I don't believe you can rely on it. I think you should consider three approaches to this; 1) Optimistic locking - assume that the seat is available and fail when you try and make a concrete booking 2) Pessimistic - tell the server you want that seat for 10 mins and will confirm later, this requires you ask the server for the lock and maintain the lock for the 10 mins 3) Don't allow specific bookings at all, tell the server you want 4 seats close together and then be told the ones you can have with a similar locking schema as (2). Long polling can still be used to augment the solution.

    http://pauliom.wordpress.com

    Wednesday, March 23, 2016 8:05 AM

All replies

  • What technology are you using for the client/server?

    http://pauliom.wordpress.com

    Thursday, February 4, 2016 9:15 AM
  • SignalR is meant for the type of requirement you have and its .NET. SignalR will push the updates out to your clients. If your client application supports web-sockets, even better. You can also scale with SignalR as well.

    If your client isn't web-based, then sure you could probably implement something yourself using the Observer Pattern.


    william xifaras

    Tuesday, March 22, 2016 4:48 PM
  • I'm not sure a long-poll technology such as SignalR is really the solution here. This is a classic airline booking problem that has been around a very long time. I'm not saying SignalR wouldn't help but I don't believe you can rely on it. I think you should consider three approaches to this; 1) Optimistic locking - assume that the seat is available and fail when you try and make a concrete booking 2) Pessimistic - tell the server you want that seat for 10 mins and will confirm later, this requires you ask the server for the lock and maintain the lock for the 10 mins 3) Don't allow specific bookings at all, tell the server you want 4 seats close together and then be told the ones you can have with a similar locking schema as (2). Long polling can still be used to augment the solution.

    http://pauliom.wordpress.com

    Wednesday, March 23, 2016 8:05 AM
  • SignalR doesn't necessarily use long-polling. Long-polling is a fallback and it will use the WebSocket transport if it can. Most modern browsers support web sockets as does Windows 8+ and .NET 4.5+.



    william xifaras


    Wednesday, March 23, 2016 2:37 PM
  • As I said, I wouldn't recommend 'relying' upon SignalR.

    http://pauliom.wordpress.com

    Thursday, March 24, 2016 6:24 AM