Fuse (design pattern)

from Wikipedia, the free encyclopedia

A fuse ( English circuit breaker ) is a pattern of behavior in the software development . It is used to avoid recurring connection errors to a resource, such as B. a database or a web service to discover and block access to the resource for a predetermined time. The backup can also be used to temporarily deactivate the functionality of the application. The concept is derived from the electrical fuse .

Background and functionality

Backup flow chart

For example, suppose a database is overloaded from too many queries and timeouts occur . This leads to the fact that users - for psychological reasons - try the last action again. Since the application waits until a timeout in a separate task for each request to the database without a backup, the thread pool is exhausted and the application also fails.

To prevent this, a fuse is built into the application. This recognizes when there are a large number of connection errors and prevents access to the database. Instead of having to wait for the database to time out, the application can immediately return an error or deactivate parts of the application, thereby not consuming any additional threads in the pool. The application can continue to run without a database and with limited functionality. In addition, it enables the database to "recover".

After a specified period of time, the backup is closed again and the connection to the database is tried again. If this attempt fails, the backup is opened again immediately. Otherwise the functionality of the application will be restored.

Since the triggering of a backup is a critical event, this should be visible in a log file , the monitoring of the application, and in an OpsDB . A separate backup is provided for each resource so that access to other resources is still possible even if access to a particular resource has failed. In addition, a backup is usually combined with a bulk head so that a separate thread pool is available for each resource.

Implementations

.NET

python

  • pybreaker. In: python.org. Retrieved March 21, 2017 (English).

Java

Individual evidence

  1. ^ Martin Fowler: Circuit Breaker. March 6, 2014, accessed March 21, 2017 .
  2. a b c Michael T. Nygard: Release It! Design and Deploy Production-Ready Software . O'Reilly, 2007, ISBN 978-0-9787392-1-8 (English, 326 pages).