### GraphQL Query Example Source: https://system-design.space/chapter/learning-graphql-book Demonstrates how to query data in GraphQL. This example fetches user information, including their name, email, and associated posts with titles and creation dates. ```graphql query { user(id: "123") { name email posts { title createdAt } } } ``` -------------------------------- ### GraphQL Subscription Example Source: https://system-design.space/chapter/learning-graphql-book Shows an example of a GraphQL subscription for real-time updates. This subscription listens for new posts and returns the ID, title, and author's name of the new post. ```graphql subscription { newPost { id title author { name } } } ``` -------------------------------- ### Kubernetes Init Container for Initialization Tasks Source: https://system-design.space/chapter/kubernetes-patterns-book Utilizes Init Containers to perform setup tasks before the main application containers start. This is useful for tasks like database migrations, waiting for dependencies, or setting up configurations. ```yaml apiVersion: v1 kind: Pod metadata: name: myapp-pod spec: containers: - name: myapp-container image: myapp:latest ports: - containerPort: 8080 initContainers: - name: init-container image: busybox command: ['sh', '-c', 'echo Initializing... && sleep 5'] ``` -------------------------------- ### GraphQL Mutation Example Source: https://system-design.space/chapter/learning-graphql-book Illustrates how to modify data using GraphQL mutations. This example shows the creation of a new post with a title and content, and returns the ID and title of the created post. ```graphql mutation { createPost(input: { title: "New Post" content: "Hello GraphQL!" }) { id title } } ``` -------------------------------- ### Kubernetes Deployment Example Source: https://system-design.space/chapter/cloud-native-book This YAML manifest defines a Kubernetes Deployment for a microservice named 'my-app'. It specifies the desired number of replicas, labels for selecting pods, and the container image to use, along with resource limits for CPU and memory. ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 3 selector: matchLabels: app: my-app template: spec: containers: - name: my-app image: my-app:v1.2.0 resources: limits: memory: "256Mi" cpu: "500m" ``` -------------------------------- ### Durability Calculation Example (Python) Source: https://system-design.space/chapter/object-storage-case Demonstrates a simplified calculation for data durability based on disk failure rates and replication strategy. Assumes annual failure rate (AFR) and the number of replicas across different failure domains. ```python # Предположим: # - Annual Failure Rate (AFR) одного диска = 2% # - 3 реплики в разных failure domains P_loss_1_disk = 0.02 P_loss_2_disks_simultaneously = P_loss_1_disk * P_loss_1_disk P_loss_3_disks_before_recovery = P_loss_2_disks_simultaneously * P_loss_1_disk # Добавляем: разные AZ, быстрое восстановление, мониторинг # → 99.999999999% durability ``` -------------------------------- ### Lifecycle Policy Configuration (JSON) Source: https://system-design.space/chapter/object-storage-case An example JSON configuration for defining lifecycle rules in an object storage system. This includes transitions to different storage classes and expiration policies based on object age and prefixes. ```json { "rules": [ { "filter": {"prefix": "logs/"}, "transitions": [ {"days": 30, "storageClass": "INFREQUENT_ACCESS"}, {"days": 90, "storageClass": "GLACIER"} ], "expiration": {"days": 365} } ] } ```