ByteByteGo 2024年07月11日
EP117: What makes HTTP2 faster than HTTP1?
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本周的系统设计回顾: Kafka vs. RabbitMQ vs. Messaging Middleware vs. Pulsar, HTTP2 比 HTTP1 更快的关键原因, 以及 Netflix 如何使用缓存来吸引用户注意力. 文章还包含了关于幂等性应用场景、日志解析命令和 API 协作的介绍.

🤔 **HTTP2 比 HTTP1 更快的原因:** HTTP2 采用二进制帧层进行编码, 将消息分割成更小的帧, 并通过 TCP 连接发送, 从而提高处理效率. 此外, HTTP2 还支持多路复用, 允许客户端和服务器在传输过程中交错帧, 并在另一端重新组装. 优先级流可以让开发者自定义请求或流的权重, 使服务器为高优先级请求发送更多帧. 服务器推送功能允许服务器在响应客户端请求时, 附带发送额外的资源. HPACK 头部压缩算法可以缩减多个请求的头部大小, 从而节省带宽. 尽管 HTTP2 拥有这些优势, 但其速度仍然取决于具体的技术场景, 开发者需要进行测试和优化, 以最大限度地发挥 HTTP2 的优势.

💡 **幂等性的应用场景:** 幂等性在各种情况下至关重要, 特别是当操作可能被重试或执行多次时. 幂等性在 RESTful API 请求、支付处理、订单管理系统、数据库操作、用户帐户管理和分布式系统与消息传递等场景中都非常重要. 幂等方法可以确保重复请求不会导致相同操作的多次执行, 从而保持资源状态的一致性.

🚀 **Netflix 如何使用缓存来吸引用户注意力:** Netflix 使用 EVCache (一个分布式键值存储) 来减少延迟, 从而保持用户对流媒体内容的兴趣. EVCache 在 Netflix 中有许多应用场景, 包括旁路缓存、瞬态数据存储、主存储和高容量数据存储. Netflix 通过缓存 UI 字符串和翻译等数据, 实现了低延迟和高可用性, 从而提升用户体验.

💻 **日志解析命令:** GREP、CUT、SED、AWK、SORT 和 UNIQ 是常用的日志解析命令. 这些命令可以组合使用, 快速从日志文件中查找有用信息. 例如, 使用 grep、cut 命令可以查找特定服务出现异常的时间戳.

🤝 **API 协作:** Postman 是一个协作 API 开发平台, 它提供 Postman Collections 和 Workspaces, 使 API 设计、测试和文档变得更加便捷, 并提供一个共享画布, 方便团队协作. Postman 帮助企业更轻松地协作, 更快地交付更好的 API.

This week’s system design refresher:


Collaborating on APIs Is Easier with Postman (Sponsored)

API Collaboration improves developer productivity by empowering producers and consumers to share, discover, and reuse high-quality API assets.

Postman revolutionizes the experience of collaborative API development with Postman Collections and Workspaces. Used together, they enable API design, testing, and documentation, while providing a shared canvas for collaborating on API assets. 

Learn how companies like Cvent, Visma, Built Technologies, and Amadeus use Postman to collaborate more easily and deliver better APIs faster.

Learn More


Kafka vs. RabbitMQ vs. Messaging Middleware vs. Pulsar


What makes HTTP2 faster than HTTP1?

The key features of HTTP2 play a big role in this. Let’s look at them:

    Binary Framing Layer
    HTTP2 encodes the messages into binary format.

    This allows the messages into smaller units called frames, which are then sent over the TCP connection, resulting in more efficient processing.

    Multiplexing
    The Binary Framing allows full request and response multiplexing.

    Clients and servers can interleave frames during transmissions and reassemble them on the other side.

    Stream Prioritization
    With stream prioritization, developers can customize the relative weight of requests or streams to make the server send more frames for higher-priority requests.

    Server Push
    Since HTTP2 allows multiple concurrent responses to a client’s request, a server can send additional resources along with the requested page to the client.

    HPACK Header Compression
    HTTP2 uses a special compression algorithm called HPACK to make the headers smaller for multiple requests, thereby saving bandwidth.

Of course, despite these features, HTTP2 can also be slow depending on the exact technical scenario. Therefore, developers need to test and optimize things to maximize the benefits of HTTP2.

Over to you: Have you used HTTP2 in your application?


Latest articles

If you’re not a paid subscriber, here’s what you missed.

    A Crash Course on Microservice Communication Patterns

    A Crash Course on Cell-based Architecture

    A Crash Course on Content-Delivery Networks (CDN)

    A Crash Course on REST APIs

    API Security Best Practices

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

Subscribe now


Top 6 Cases to Apply Idempotency

Idempotency is essential in various scenarios, particularly where operations might be retried or executed multiple times. Here are the top 6 use cases where idempotency is crucial:

    RESTful API Requests
    We need to ensure that retrying an API request does not lead to multiple executions of the same operation. Implement idempotent methods (like PUT and DELETE) to maintain consistent resource states.

    Payment Processing
    We need to ensure that customers are not charged multiple times due to retries or network issues. Payment gateways often need to retry transactions; idempotency ensures only one charge is made.

    Order Management Systems
    We need to ensure that submitting an order multiple times results in only one order being placed. We design a safe mechanism to prevent duplicate inventory deductions or updates.

    Database Operations
    We need to ensure that reapplying a transaction does not change the database state beyond the initial application.

    User Account Management
    We need to ensure that retrying a registration request does not create multiple user accounts. Also, we need to ensure that multiple password reset requests result in a single reset action.

    Distributed Systems and Messaging
    We need to ensure that reprocessing messages from a queue does not result in duplicate processing. We Implement handlers that can process the same message multiple times without side effects.


4 Ways Netflix Uses Caching to Hold User Attention

The goal of Netflix is to keep you streaming for as long as possible. But a user’s typical attention span is just 90 seconds.

They use EVCache (a distributed key-value store) to reduce latency so that the users don’t lose interest.

However, EVCache has multiple use cases at Netflix.

    Lookaside Cache
    When the application needs some data, it first tries the EVCache client and if the data is not in the cache, it goes to the backend service and the Cassandra database to fetch the data.

    The service also keeps the cache updated for future requests.

    Transient Data Store
    Netflix uses EVCache to keep track of transient data such as playback session information.

    One application service might start the session while the other may update the session followed by a session closure at the very end.

    Primary Store
    Netflix runs large-scale pre-compute systems every night to compute a brand-new home page for every profile of every user based on watch history and recommendations.

    All of that data is written into the EVCache cluster from where the online services read the data and build the homepage.

    High Volume Data
    Netflix has data that has a high volume of access and also needs to be highly available. For example, UI strings and translations that are shown on the Netflix home page.

    A separate process asynchronously computes and publishes the UI string to EVCache from where the application can read it with low latency and high availability.

Reference: "Caching at Netflix: The Hidden Microservice" by Scott Mansfield


Log Parsing Cheat Sheet

The diagram below lists the top 6 log parsing commands.

    GREP
    GREP searches any given input files, selecting lines that match one or more patterns.

    CUT
    CUT cuts out selected portions of each line from each file and writes them to the standard output.

    SED
    SED reads the specified files, modifying the input as specified by a list of commands.

    AWK
    AWK scans each input file for lines that match any of a set of patterns.

    SORT
    SORT sorts text and binary files by lines.

    UNIQ
    UNIQ reads the specified input file comparing adjacent lines and writes a copy of each unique input line to the output file.

These commands are often used in combination to quickly find useful information from the log files. For example, the below commands list the timestamps (column 2) when there is an exception happening for xxService.

grep “xxService” service.log | grep “Exception” | cut -d” “ -f 2

Over to you: What other commands do you use when you parse logs?


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 hi@bytebytego.com

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

系统设计 Kafka RabbitMQ Messaging Middleware Pulsar HTTP2 幂等性 Netflix 缓存 日志解析 API 协作 Postman
相关文章