1 year ago
#375884
Mateusz Gebroski
Observer design Pattern - Struggling with real world backend cases
Good Morning / Evening :)
I am studying design patterns and I am now and a section with Observer pattern.
I understand how does it work but I am struggling with finding real world sample.
Most of samples on the Google are something like frontend'ish social media components or when cat does meow dogs goes angry (lol) which is not what I am looking for because I am mainly trying to specialise in backend so I would like to find piece of backend system code that maybe you guys have used or you are thinking about. I strongly believe this is my lack of creativity.
Could you help me with that?
I am not even asking for real code samples but just an idea where it could be used.
I found that all reactive stuff like RxJS library or even NODE'JS EventEmitter are observer like but is that really all?
What about implementing concrete pieces of systems?
I believe that it might be maybe used in some bidding or ticketing systems?
For example bidding system.
There is a database table with concrete auction (Subject) where max bid is 150$ for something. There is table Users where there are 4 Users (Observers) that has set max bid limits like 150,160,165,170$. Flow: There are 4 Users in auction and current max bid is 150$ which belong to first User. Another new User does http POST method, joins the auction and sets max bid limit of an auction to 151. Auction (Subject), add new User to the list of Observers and then notifies Users that already belongs to auction that max bid was raised. Each User checks if this bid is lower or equal its max bid limit. When user is allowed to bid higher it bids higher until someone will actually won auction. Does it make sense? I believe that I should think different because Users should't be components builded with code. We could do just query to database and just find Users which belongs to auction and can bid higher :/
I would like to find some architectural components where this pattern can be used.
Thank you
design-patterns
reactive-programming
observer-pattern
0 Answers
Your Answer