chartletv0.21.0chartlet.casoon.de

← All examples

Reading an item through the cache

Five participants, each kind in its own shape, and ten numbered messages: calls with filled heads activate their receiver until it replies with a dashed line, asynchronous messages have open heads, and an alt fragment frames the cached and the uncached branch. The description and the data table list every message in order.

Reading an item through the cache

examples/cache-lookup.json
{
  "schemaVersion": 1,
  "type": "sequence",
  "title": "Reading an item through the cache",
  "source": "Service handbook, request flow",
  "width": 800,
  "height": 670,
  "sequence": {
    "participants": [
      {
        "id": "user",
        "label": "Reader",
        "kind": "actor"
      },
      {
        "id": "api",
        "label": "Item API",
        "sublabel": "HTTP :8080"
      },
      {
        "id": "cache",
        "label": "Cache",
        "sublabel": "in memory",
        "kind": "database"
      },
      {
        "id": "db",
        "label": "Item store",
        "sublabel": "Postgres",
        "kind": "database"
      },
      {
        "id": "events",
        "label": "Change feed",
        "kind": "queue"
      }
    ],
    "messages": [
      {
        "from": "user",
        "to": "api",
        "label": "GET /items/42"
      },
      {
        "from": "api",
        "to": "api",
        "label": "check token"
      },
      {
        "from": "api",
        "to": "cache",
        "label": "get item:42"
      },
      {
        "from": "cache",
        "to": "api",
        "label": "hit",
        "kind": "reply"
      },
      {
        "from": "cache",
        "to": "api",
        "label": "miss",
        "kind": "reply"
      },
      {
        "from": "api",
        "to": "db",
        "label": "SELECT item 42"
      },
      {
        "from": "db",
        "to": "api",
        "label": "row",
        "kind": "reply"
      },
      {
        "from": "api",
        "to": "cache",
        "label": "set item:42, 5 min",
        "kind": "async"
      },
      {
        "from": "api",
        "to": "events",
        "label": "item.read",
        "kind": "async"
      },
      {
        "from": "api",
        "to": "user",
        "label": "200 OK",
        "kind": "reply"
      }
    ],
    "fragments": [
      {
        "kind": "alt",
        "label": "cached",
        "from": 3,
        "to": 7,
        "else": [
          {
            "from": 4,
            "label": "not cached"
          }
        ]
      }
    ],
    "numbered": true
  }
}
Focus
Reading an item through the cache
Reading an item through the cacheSequence diagram with 5 participants: Reader (actor), Item API, Cache (database), Item store (database) and Change feed (queue). 10 messages, in order: 1. Reader to Item API: GET /items/42. 2. Item API to itself: check token. 3. Item API to Cache: get item:42. 4. Cache to Item API: hit (reply). 5. Cache to Item API: miss (reply). 6. Item API to Item store: SELECT item 42. 7. Item store to Item API: row (reply). 8. Item API to Cache: set item:42, 5 min (asynchronous). 9. Item API to Change feed: item.read (asynchronous). 10. Item API to Reader: 200 OK (reply). Fragment alt "cached" spans messages 4–8, else "not cached" from message 5.alt[cached][not cached]1. Reader → Item API: GET /items/42GET /items/4212. Item API → Item API: check tokencheck token23. Item API → Cache: get item:42get item:4234. Cache → Item API: hithit45. Cache → Item API: missmiss56. Item API → Item store: SELECT item 42SELECT item 4267. Item store → Item API: rowrow78. Item API → Cache: set item:42, 5 minset item:42, 5 min89. Item API → Change feed: item.readitem.read910. Item API → Reader: 200 OK200 OK10ReaderReaderItem API – HTTP :8080Item APIHTTP :8080Cache – in memoryCachein memoryItem store – PostgresItem storePostgresChange feedChange feed

Source: Service handbook, request flow

Show chart data
Data for Reading an item through the cache
No.FromToMessageKindFragment
1ReaderItem APIGET /items/42call
2Item APIItem APIcheck tokencall
3Item APICacheget item:42call
4CacheItem APIhitreplyalt [cached]
5CacheItem APImissreplyalt [not cached]
6Item APIItem storeSELECT item 42callalt [not cached]
7Item storeItem APIrowreplyalt [not cached]
8Item APICacheset item:42, 5 minasynchronousalt [not cached]
9Item APIChange feeditem.readasynchronous
10Item APIReader200 OKreply
  • Sequence diagram
  • Explain a request flow