Algo Deck

repository·master·Indexed 26 days ago

https://github.com/teivah/algodeck

A project providing algorithm visualization and system design learning materials, hosted at deckly.dev. It includes the Algo Deck and Design Deck, covering topics such as caching patterns (Cache-aside, Read-through), database properties (ACID, CAP, PACELC), partitioning and replication strategies, CRDTs, storage engines (LSM-trees vs B-trees), and distributed system patterns like Sagas and the Outbox pattern.

Tokens
5.2K
Snippets
0
Records
44
Agent score
41%

What's inside algodeck

  1. Understand the Mutual TLS (mTLS) handshake

    master

    Mutual TLS adds client authentication using a certificate. The handshake process is as follows:

    1. Client hello: Client sends protocol and cipher details.
    2. Server hello: Server sends supported ciphers.
    3. Server certificate: Server sends its certificate.
    4. Server certificate validation: Client checks the server certificate (e.g., verifying the CA is trusted in its truststore).
    5. Client certificate: Client sends its certificate.
    6. Client certificate validation: Server checks the client certificate.
    7. Session key generation: The client generates a session key, encrypts it with the public key of the client certificate (asymmetric encryption), and sends it to the server.
    8. Data transmission: The client sends data, encrypting each packet using the session key (symmetric encryption).

    Note: In one variation, the session key is generated by the client.

  2. Implement a Saga for distributed transactions

    master

    A Saga is a distributed transaction composed of a sequence of local transactions. To ensure consistency:

    • Each local transaction must have a corresponding compensation action to undo its changes if a subsequent step fails.
    • Sagas are typically managed by an orchestrator that coordinates the execution of transactions and triggers compensations when necessary.
  3. Access Anki flashcard versions of Algo Deck and Design Deck

    master

    Anki-compatible versions (clones of the flashcards from this repository) are available through one-time GitHub sponsorships. You can choose between individual decks or a bundle:

    • Algo Deck: Available via the $19 tier.
    • Design Deck: Available via the $21 tier.
    • Algo Deck and Design Deck (Bundle): Available via the $29 tier.
  4. Implement Partitioning (Sharding) strategies

    master

    Partitioning splits large datasets across multiple machines. Choose a strategy based on your primary access pattern:

    • Range Partitioning: Keys are sorted; a partition owns a range (e.g., min to max).
      • Pros: Efficient range queries.
      • Cons: Risk of hot spots; requires repartitioning if a range grows too large.
    • Hash Partitioning: A hash function is applied to each key to determine its partition.
      • Pros: Better distribution of data.
    • Horizontal Partitioning: Partitioning by rows.
    • Vertical Partitioning: Partitioning by columns (e.g., moving large blobs to a separate table to improve primary disk performance).
  5. Implement the Outbox pattern for transactional event publishing

    master

    Use the Outbox pattern to ensure that database updates and event publishing happen atomically. Within a single database transaction:

    1. Perform your data operation (insert, update, or delete).
    2. Insert a new row into a dedicated event table containing the event details.

    Then, implement a separate worker process that:

    • Polls the event table.
    • Publishes the event to your message broker.
    • Deletes the row from the event table.

    This provides an at-least-once delivery guarantee.

  6. Implement Cache-aside pattern

    master
    In a Cache-aside pattern, the application is responsible for both reading from and writing to the database. The cache does not interact with the storage directly. This pattern allows the data model in the cache to differ from the data model in the database.
  7. Understand OAuth 2 authentication process

    master

    OAuth 2 is a standard for access delegation. The process follows these steps:

    1. The client obtains a token from an authorization server.
    2. The client makes a request to a server using that token.
    3. The server validates the token with the authorization server.

    Note: Some token types, such as JWT (JSON Web Tokens), are self-contained, allowing the server to perform validation locally without calling the authorization server.

  8. Choose a Replication strategy

    master

    Select a replication model based on your system's requirements for consistency and write throughput:

    • Single-leader: All writes go to one leader. Ensures high consistency but creates a write bottleneck.
    • Multi-leader: Multiple leaders (often one per datacenter). Good for multi-datacenter setups or offline clients, but requires conflict resolution.
    • Leaderless: Clients send writes/reads to multiple replicas in parallel. High throughput and availability, but consistency is harder to guarantee (relies on quorums, read repair, and anti-entropy).
  9. Avoid Retry Amplification in dependency chains

    master

    Retry amplification occurs when retries are implemented at multiple levels of a service dependency chain. This significantly increases the load on the deepest services in the chain.

    Best Practice: In long dependency chains, avoid retrying at every level. Instead, consider retrying at only a single level of the chain to prevent exponential load growth on downstream services.

  10. Use HyperLogLog for cardinality approximation

    master

    HyperLogLog is used to approximate the cardinality (number of unique elements) of a set with high space efficiency (memory requirement is log(log(m)) where m is the number of unique visitors).

    Implementation Details

    • Core Logic: For an ID, count the number of consecutive leading zero bits. If the count is n, the average number of attempts to see that pattern is 2^n + 1.
    • Requirement: Input IDs must be uniform (e.g., randomly generated or hashed).
    • Accuracy Improvement (Bucketing): To reduce the impact of outliers, distribute IDs into multiple counters using the first few bits of the ID and aggregate the results using the harmonic mean.
  11. Use Exponential Backoff and Jitter for retries

    master

    When handling transient failures, use these strategies to avoid overwhelming a recovering system:

    • Exponential Backoff: Increase the wait time between retry attempts exponentially (e.g., 1s, 2s, 4s, 8s) rather than using a fixed interval.
    • Jitter: Introduce randomness into the backoff intervals. This prevents 'synchronized retry spikes' where many clients retry at the exact same moment, which can trigger cascading failures.