concept component in category scala

appears as: components, component, components, A component, component, The components, The component
Reactive Design Patterns

This is an excerpt from Manning's book Reactive Design Patterns.

The result of this process will be a hierarchy of components that need to be developed and deployed. An example is shown in figure 1.2. Each component may be complex in terms of its function, such as the implementation of search algorithms; or it may be complex in its deployment and orchestration, such as providing email storage for billions of users. But it will always be simple to describe in terms of its responsibility.

A component shall do only one thing, but do it in full.

Listing 12.2. Protecting a component by using a rate limiter
import scala.concurrent.duration.FiniteDuration import scala.concurrent.duration.Deadline import scala.concurrent.Future case object RateLimitExceeded extends RuntimeException class RateLimiter(requests: Int, period: FiniteDuration) {   private val startTimes = {     val onePeriodAgo = Deadline.now - period     Array.fill(requests)(onePeriodAgo)   }   private var position = 0 #1   private def enqueue(time: Deadline) = {     startTimes(position) = time     position += 1     if (position == requests) position = 0   }   def call[T](block: => Future[T]): Future[T] = {     val now = Deadline.now #2     if ((now - startTimes(position)) < period) {       Future.failed(RateLimitExceeded)     } else {       enqueue(now)       block     }   } } #1 - Index of the next slot to be used, keeping track of when the last job was enqueued in it to enforce the rate limit #2 - Obtains the current timestamp
  • Your system consists of components that have different reliability requirements.
  • You expect components to have significantly different failure probabilities and failure severities.
  • The system has important functionality that it must provide as reliably as possible while also having components that are exposed to failure.
  • Scala in Action

    This is an excerpt from Manning's book Scala in Action.

  • Abstractions— This is the focus of this chapter. You’ll learn how the type system provides abstractions to build components.