Skip to content

Instantly share code, notes, and snippets.

microservice(MS)

1つのアプリケーションを機能別にAPIとして切り出したもの。大規模化・複雑化が進むにつれ、開発コストおよび新規メンバーの参入コストが高くなるため、2014年頃から流行りだした。対して、もともとの1枚岩のアプリケーションはmonolithicと呼ばれる。日本だとモノリスとも言われる。

microserviceのデメリット

小さくなったのは良いが、「連携設定」「APIのセキュリティ」「リトライ処理」などコストが増した。また、個数の増加に伴い、新しいMSを追加したときの影響範囲も分かりづらく、それらを解消するために「監視体制」「サーキットブレイク」なども必要となり、複雑性を増していった。

microserviceの課題

@maiha
maiha / raven.cr.md
Created March 1, 2021 08:42
raven : An unofficial Crystal-language client and integration layer for the Sentry error reporting API.
    private def current_environment_from_env
      ENV["SENTRY_ENVIRONMENT"]? || "default"
 
    private def detect_release_from_env
      ENV["SENTRY_RELEASE"]?

Let's consider some value holder. For example, Try monad. For simplicity, Let's assume it only works with Int32.

record Success, value : Int32
record Failure, value : Exception

# some try object
try : Success | Failure = Success(1)
@maiha
maiha / document-as-interface.md
Created February 9, 2021 10:01
Type safe documenting

Abstract

Use the interface to prevent missing documents.

Example

class SomeLib
  module Interface
    abstract def foo : String
 abstract def bar : String
@maiha
maiha / RateLimit.md
Last active January 15, 2024 02:02
RateLimitアルゴリズムまとめまとめ (→ Sliding window countersでOK)

TL;DR

  • Leaky bucket : キューイングして出力量(consume)で調節 (アルゴリズムというかキューを使って調節)
  • Token bucket : 定期的に資源を追加し平均値を調節。バーストに強い (ソシャゲのスタミナ回復)
  • Fixed window counters : 単位時間あたりの上限値を指定。キューを使わないLeaky bucket。境界の2倍問題あり
  • Sliding window log : 総数(counters)でなくアクセス時刻(log)で管理。境界問題を解消する一方、消費増加がぱない(IntArray(Time))
  • Sliding window counters : countersのままで、単位時間の割合計算によって境界問題を解消。これにしておけば間違いない

参考: 様々なrate limitアルゴリズム

/dev/vdb があることを確認

$ fdisk -l
...
Disk /dev/vdb: 2 TiB, 2147483648000 bytes, 4194304000 sectors
...

パーティション作成(2TB以下の場合)

Typical Operations

a ?? b # => a.typical_zero? ? b : a

def T#typical_zero?
  self == T.typical_zero
def T.typical_zero
  nil
@maiha
maiha / SQS.md
Last active January 7, 2021 01:36