Destroys failures.
Scala
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
failurewall-akka/src
failurewall-benchmark/src/test
failurewall-core/src
failurewall-patterns/src
failurewall-sample/src/main/scala/sample/failurewall
project
.travis.yml
LICENSE
README.md
build.sbt
publish.sh

README.md

Failurewall

Build Status

This is a library to protect applications against failures, and helpful in developing stable, responsive and resilient systems.

Failurewall is inspired by Hystrix and adapted for scala.concurrent.Future.

Getting Started

You should add the following dependency.

libraryDependencies += "com.okumin" %% "failurewall-core" % "0.1.0"

If you are using Akka 2.4, you can use failurewall-akka. failurewall-akka provides the following failurewalls.

  • circuit breaker
  • timeout
  • retry with backoff
libraryDependencies += "com.okumin" %% "failurewall-akka" % "0.1.0"

If you are using Akka 2.3, see also failurewall-akka23.

How to use

As a Proxy

Failurewall is simple to use, wrapping scala.concurrent.Future to be protected. Each failurewall has abilities to handle failures.

object HttpClient {
  def get(url: String): Future[Response] = ???
}

val failurewall: Failurewall[Response, Response] = ???
val response: Future[Response] = failurewall.call(HttpClient.get("http://okumin.com/"))

Composability

Failurewalls has their own ability, e.g. retrying, checking rate limits and throttling. Failurewall#compose makes Failurewalls decorate such features.

val wallSina: Failurewall[Int, String] = ???
val wallRose: Failurewall[Int, Int] = ???
val wallMaria: Failurewall[Double, Int] = ???

val walls: [Double, String] = wallSina compose wallRose compose wallMaria

Build-in walls

This library provides some of Failurewalls to handle failures.

Retry

RetryFailurewall lets requests recover from temporary failures.

val executor: ExecutionContext = ???
val failurewall = RetryFailurewall[Response](10, executor)
failure.call(Future.failed(new RuntimeException)) // retry 10 times

Semaphore

StdSemaphoreFailurewall keeps resource usage constant.

val executor: ExecutionContext = ???
val failurewall = StdSemaphoreFailurewall[Response](10, executor)
val results = (1 to 100).map { _ =>
  // fails immediately while 10 calls are blocking
  failurewall.call(Promise[Response].future)
}

Circuit breaker

AkkaCircuitBreakerFailurewall prevents a failure from leading to cascading other failures.

val executor: ExecutionContext = ???
// has a little complicated constructor
val failurewall: AkkaCircuitBreakerFailurewall[Response] = ???
val results = (1 to 100).map { _ =>
  // fail-fast after failure times exceeds the threshold
  failurewall.call(Future {
    Thread.sleep(1000)
    throw new RuntimeException
  })
}

For microservices

MicroserviceFailurewall consists of a circuit breaker, a semaphore and a retry pattern.

val failurewall = MicroserviceFailurewall[Response](???, ???, ???, ???)
// protected by the composed wall
failurewall.call(HttpRequest.get("http://okumin.com/"))