EP118: What are the differences among database locks?

This weekโ€™s system design refresher:


Ship every native SaaS integration your users need (Sponsored)

Is product asking your team to build native product integrations with 3rd party services (ie. Salesforce, Slack, etc.)?

Save 70% of the engineering effort with Paragon, so you can stay focused on your core competencies.

Offload the plumbing around integrations with:

See how 100+ SaaS companies orchestrate ingestion jobs, real-time sync, and event-driven automations with 3rd party SaaS apps in weeks, not months.

Learn more


What are the differences among database locks?

In database management, locks are mechanisms that prevent concurrent access to data to ensure data integrity and consistency.

No alternative text description for this image

Here are the common types of locks used in databases:

  1. Shared Lock (S Lock)
    It allows multiple transactions to read a resource simultaneously but not modify it. Other transactions can also acquire a shared lock on the same resource.

  2. Exclusive Lock (X Lock)
    It allows a transaction to both read and modify a resource. No other transaction can acquire any type of lock on the same resource while an exclusive lock is held.

  3. Update Lock (U Lock)
    It is used to prevent a deadlock scenario when a transaction intends to update a resource.

  4. Schema Lock
    It is used to protect the structure of database objects.

  5. Bulk Update Lock (BU Lock)
    It is used during bulk insert operations to improve performance by reducing the number of locks required.

  6. Key-Range Lock
    It is used in indexed data to prevent phantom reads (inserting new rows into a range that a transaction has already read).

  7. Row-Level Lock
    It locks a specific row in a table, allowing other rows to be accessed concurrently.

  8. Page-Level Lock
    It locks a specific page (a fixed-size block of data) in the database.

  9. Table-Level Lock
    It locks an entire table. This is simple to implement but can reduce concurrency significantly.


How do we Perform Pagination in API Design?

No alternative text description for this image

Pagination is crucial in API design to handle large datasets efficiently and improve performance. Here are six popular pagination techniques:


Latest articles

If youโ€™re not a paid subscriber, hereโ€™s what you missed.

  1. A Crash Course in Database Sharding

  2. A Crash Course on Microservice Communication Patterns

  3. A Crash Course on Cell-based Architecture

  4. A Crash Course on Content-Delivery Networks (CDN)

  5. A Crash Course on REST APIs

To receive all the full articles and support ByteByteGo, consider subscribing:

Subscribe now


What distinguishes MVC, MVP, MVVM, MVVM-C, and VIPER architecture patterns from each other?

No alt text provided for this image

These architecture patterns are among the most commonly used in app development, whether on iOS or Android platforms. Developers have introduced them to overcome the limitations of earlier patterns. So, how do they differ?


What happens when you type a URL into your browser?

The diagram below illustrates the steps.

No alt text provided for this image
  1. Bob enters a URL into the browser and hits Enter. In this example, the URL is composed of 4 parts:
    ๐Ÿ”น scheme - ๐’‰๐’•๐’•๐’‘://. This tells the browser to send a connection to the server using HTTP.
    ๐Ÿ”น domain - ๐’†๐’™๐’‚๐’Ž๐’‘๐’๐’†.๐’„๐’๐’Ž. This is the domain name of the site.
    ๐Ÿ”น path - ๐’‘๐’“๐’๐’…๐’–๐’„๐’•/๐’†๐’๐’†๐’„๐’•๐’“๐’Š๐’„. It is the path on the server to the requested resource: phone.
    ๐Ÿ”น resource - ๐’‘๐’‰๐’๐’๐’†. It is the name of the resource Bob wants to visit.

  2. The browser looks up the IP address for the domain with a domain name system (DNS) lookup. To make the lookup process fast, data is cached at different layers: browser cache, OS cache, local network cache, and ISP cache.

    2.1 If the IP address cannot be found at any of the caches, the browser goes to DNS servers to do a recursive DNS lookup until the IP address is found (this will be covered in another post).

  3. Now that we have the IP address of the server, the browser establishes a TCP connection with the server.

  4. The browser sends an HTTP request to the server. The request looks like this:

    ๐˜Ž๐˜Œ๐˜› /๐˜ฑ๐˜ฉ๐˜ฐ๐˜ฏ๐˜ฆ ๐˜๐˜›๐˜›๐˜—/1.1
    ๐˜๐˜ฐ๐˜ด๐˜ต: ๐˜ฆ๐˜น๐˜ข๐˜ฎ๐˜ฑ๐˜ญ๐˜ฆ.๐˜ค๐˜ฐ๐˜ฎ

  5. The server processes the request and sends back the response. For a successful response (the status code is 200). The HTML response might look like this:

    ๐˜๐˜›๐˜›๐˜—/1.1 200 ๐˜–๐˜’
    ๐˜‹๐˜ข๐˜ต๐˜ฆ: ๐˜š๐˜ถ๐˜ฏ, 30 ๐˜‘๐˜ข๐˜ฏ 2022 00:01:01 ๐˜Ž๐˜”๐˜›
    ๐˜š๐˜ฆ๐˜ณ๐˜ท๐˜ฆ๐˜ณ: ๐˜ˆ๐˜ฑ๐˜ข๐˜ค๐˜ฉ๐˜ฆ
    ๐˜Š๐˜ฐ๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ต-๐˜›๐˜บ๐˜ฑ๐˜ฆ: ๐˜ต๐˜ฆ๐˜น๐˜ต/๐˜ฉ๐˜ต๐˜ฎ๐˜ญ; ๐˜ค๐˜ฉ๐˜ข๐˜ณ๐˜ด๐˜ฆ๐˜ต=๐˜ถ๐˜ต๐˜ง-8

    <!๐˜‹๐˜–๐˜Š๐˜›๐˜ ๐˜—๐˜Œ ๐˜ฉ๐˜ต๐˜ฎ๐˜ญ>
    <๐˜ฉ๐˜ต๐˜ฎ๐˜ญ ๐˜ญ๐˜ข๐˜ฏ๐˜จ="๐˜ฆ๐˜ฏ">
    ๐˜๐˜ฆ๐˜ญ๐˜ญ๐˜ฐ ๐˜ธ๐˜ฐ๐˜ณ๐˜ญ๐˜ฅ
    </๐˜ฉ๐˜ต๐˜ฎ๐˜ญ>

  6. The browser renders the HTML content.


How do you pay from your digital wallet, such as Paypal, Venmo, Paytm, by scanning the QR code?

diagram

To understand the process involved, we need to divide the โ€œscan to payโ€ process into two sub-processes:

  1. Merchant generates a QR code and displays it on the screen

  2. Consumer scans the QR code and pays

Here are the steps for generating the QR code:

  1. When you want to pay for your shopping, the cashier tallies up all the goods and calculates the total amount due, for example, $123.45. The checkout has an order ID of SN129803. The cashier clicks the โ€œcheckoutโ€ button.

  2. The cashierโ€™s computer sends the order ID and the amount to PSP.

  3. The PSP saves this information to the database and generates a QR code URL.

  4. PSPโ€™s Payment Gateway service reads the QR code URL.

  5. The payment gateway returns the QR code URL to the merchantโ€™s computer.

  6. The merchantโ€™s computer sends the QR code URL (or image) to the checkout counter.

  7. The checkout counter displays the QR code.

These 7 steps complete in less than a second. Now itโ€™s the consumerโ€™s turn to pay from their digital wallet by scanning the QR code:

  1. The consumer opens their digital wallet app to scan the QR code.

  2. After confirming the amount is correct, the client clicks the โ€œpayโ€ button.

  3. The digital wallet App notifies the PSP that the consumer has paid the given QR code.

  4. The PSP payment gateway marks this QR code as paid and returns a success message to the consumerโ€™s digital wallet App.

  5. The PSP payment gateway notifies the merchant that the consumer has paid the given QR code.


SPONSOR US

Get your product in front of more than 500,000 tech professionals.

Our newsletter puts your products and services directly in front of an audience that matters - hundreds of thousands of engineering leaders and senior engineers - who have influence over significant tech decisions and big purchases.

Space Fills Up Fast - Reserve Today

Ad spots typically sell out about 4 weeks in advance. To ensure your ad reaches this influential audience, reserve your space now by emailing [email protected]