10. Design Logging System | Chain of Responsibility Design Pattern | Amazon System Design interview

preview_player
Показать описание
This Chain of responsibility Design pattern has been asked in Amazon and many other top product based companies.
This pattern is used for many real time application usage like ATM design, Vending Machine design and Logging System design

➡️ Code (GitLab) Link:
Shared in the Member Community Post (If you are Member of this channel, then pls check the Member community post, i have shared the Git link there)

Рекомендации по теме
Комментарии
Автор

This is where we actually implement a Linked List from scratch to solve a real world problem!! And this proves why understanding datastructures from scratch is important and not simply use library classes. Great video!! 💯

rishabhshekharphukan
Автор

Spring Security Filter chain is the perfect example of this Design pattern in my opinion..where your authentication request goes through multiple Authentication Provider

сойка-ий
Автор

How to decide when to use if-else / switch-case and when to use chain of responsibility pattern?
Like in case of logger since we already know about all the handlers and the chain order in advance why not use if-else statement for each log level

arunshrivastava
Автор

Hey just a question, why can't we have three different objects and use something like a factory pattern to dynamically select the object on basis of some string(info, debug or error) and then invoke that object's logging function.
Why do we need to maintain a chain of responsibility

vishalbhardwaj
Автор

highly underrated playlist for System design interview prep.

vnitish
Автор

idk but does this design pattern really helps? The problem it is trying to solve can be easily solved by data structure or even by if else conditions if levels are not too many.
why i would want the flow to reach it to error via info or log when i can reach there directly?
or in vending machine if i want water why do i want the flow go via pepsi or coke??

goelshubham
Автор

apki understanding bahot acchi hai. mujhe kafi benifit mila

Rakeshkumar-poyg
Автор

great example. Just one question, why can't we use switch case here to get exact match of that object type and call its method? if none is found, default case would return.

manishbansal
Автор

Man, you're the best person for this content❤❤❤ . Definitely recommending this channel to many.

jayantjain
Автор

Why do we use abstract class instead of normal class in Responsibility chain design pattern, when we don't have any abstract methods inside it?

maggs
Автор

great video. one doubt is, cant we use simple factory pattern also to solve logger question ? based on log type in request, factory will return corresponding logger class and we will call log method in that class

pulakammalathy
Автор

there are folks in the comment section questioning if COR is the right pattern for logger or it can be done differently, here is my two cents on this, reason why chain of responsibility is the right pattern here: let's take example of log4j, we can enable certain log level in the system like ERROR or INFO etc, this is how the error levels are defined ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF e.g. if log level is set to warn, then only warn, error, fatal will be printed, rest all logs with other log levels will be disabled like debug, info etc will not be printed

Now you can see that chain of responsibility comes in handy here, lets say I have used warn as log level in log 4j and in code i have different logs like debug, info, error etc lets take error, it will go to all handlers and check what log level is enabled e.g. it will first go to debug handler, is it enabled, no, then go to next info and next warn, okay warn is enabled but the log level to be printed is error, then it will move to next handler i.e. error okay now it matches the log level to be printed and also at the system level warn is enabled and error handler is eligible for printing this log

There is a order of execution here where the request may or may not be fulfilled based on what log level is enabled and the order which the request should be served is defined by the chain of responsibility pattern i.e. ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF

zishanshaikh
Автор

Awesome explanation.
can you help me understand why we prefer this design pattern over just simple if/else in the base class to create different logger object? to avoid unnecessary iteration over complete list

rishiagrawal_mtr
Автор

great explanation... thanks sir ji...
though the video length is 15min only.. one might need to spend more time understanding how this chain is transferring their responsibilities to next chained object.

vyankateshkulkarni
Автор

first of all, doing great work.
I have a suggestion that it should not be the responsibility of main method to invoke the info or debug logger rather the logProcessor should be responsible of creating the chain of log processors and main method just invoke the logger and then calls it for printing logs

kashifjamil
Автор

Why not use a factory pattern here, based on Log level, we can get the instance of the logger which implements it, and use that logger to log? Why is this approach better here and not factory?

anshulkatare
Автор

Hey @shreyansh, can we also use factory pattern for logging as in the video itself the logging level can be determined using the type like info, debug or error and based on the type the implementing class can print the statement ? Just curious about the different approach in this logging specific problem. Although I understood the case where the rs 2000 were being fetched from ATM.

theaverageladka
Автор

Sir, please some video like parking lot for everyone

ROHANKUMAR_
Автор

For the logger method, we could have simply used Factory design pattern to determine the correct logger as per the enum passed, why do we need a chain of responsibility pattern? In this scenario, why should an error message be even processed by InfoLogProcessor?

ujjwalgupta
Автор

this one was epic, agar iske alawa bhi aata he to 😂

kushalsheth