<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>后端开发 on Chen Shungen</title><link>https://chenshungen.cn/tags/%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91/</link><description>Recent content in 后端开发 on Chen Shungen</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Wed, 15 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://chenshungen.cn/tags/%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91/index.xml" rel="self" type="application/rss+xml"/><item><title>Go 语言后端开发实践总结</title><link>https://chenshungen.cn/blog/golang-backend/</link><pubDate>Wed, 15 Apr 2026 00:00:00 +0000</pubDate><guid>https://chenshungen.cn/blog/golang-backend/</guid><description>&lt;h2 id="为什么选择-go">为什么选择 Go？&lt;/h2>
&lt;p>Go 语言在后端开发中的优势不言而喻：&lt;/p>
&lt;ul>
&lt;li>&lt;strong>编译速度快&lt;/strong>：秒级编译，开发体验流畅&lt;/li>
&lt;li>&lt;strong>并发原语优秀&lt;/strong>：goroutine + channel 模型简洁强大&lt;/li>
&lt;li>&lt;strong>部署简单&lt;/strong>：单二进制文件，无依赖&lt;/li>
&lt;li>&lt;strong>性能优异&lt;/strong>：接近 C 的性能，远超脚本语言&lt;/li>
&lt;/ul>
&lt;h2 id="项目结构推荐">项目结构推荐&lt;/h2>
&lt;div class="highlight-wrapper">
 &lt;button class="copy-code-btn" type="button" aria-label="Copy code to clipboard">
 &lt;svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
 &lt;rect x="9" y="9" width="13" height="13" rx="2" ry="2">&lt;/rect>
 &lt;path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1">&lt;/path>
 &lt;/svg>
 &lt;span class="copy-text">Copy&lt;/span>
 &lt;/button>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">project/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── cmd/ # 应用入口
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ └── server/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ └── main.go
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── internal/ # 内部包（不对外暴露）
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ ├── handler/ # HTTP 处理器
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ ├── service/ # 业务逻辑
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ ├── repository/ # 数据访问
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ └── model/ # 数据模型
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── pkg/ # 可复用的公共包
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── api/ # API 定义（proto/openapi）
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── config/ # 配置文件
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">└── deploy/ # 部署相关&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/div>
&lt;h2 id="错误处理模式">错误处理模式&lt;/h2>
&lt;p>Go 的错误处理虽然冗长，但有其设计哲学。推荐的做法：&lt;/p></description></item><item><title>分布式系统设计要点</title><link>https://chenshungen.cn/blog/distributed-systems/</link><pubDate>Tue, 14 Apr 2026 00:00:00 +0000</pubDate><guid>https://chenshungen.cn/blog/distributed-systems/</guid><description>&lt;h2 id="分布式系统的核心挑战">分布式系统的核心挑战&lt;/h2>
&lt;p>分布式系统面临的根本挑战可以用 CAP 定理来概括——一致性（Consistency）、可用性（Availability）、分区容错性（Partition Tolerance）三者不可兼得。&lt;/p>
&lt;p>在实际工程中，我们几乎总是需要保证分区容错性，因此核心的权衡在于：&lt;/p>
&lt;ul>
&lt;li>&lt;strong>CP 系统&lt;/strong>：优先一致性，如 ZooKeeper、etcd&lt;/li>
&lt;li>&lt;strong>AP 系统&lt;/strong>：优先可用性，如 Cassandra、DynamoDB&lt;/li>
&lt;/ul>
&lt;h2 id="服务间通信">服务间通信&lt;/h2>
&lt;p>常见的服务间通信方式：&lt;/p>
&lt;table>
 &lt;thead>
 &lt;tr>
 &lt;th>方式&lt;/th>
 &lt;th>适用场景&lt;/th>
 &lt;th>优势&lt;/th>
 &lt;th>劣势&lt;/th>
 &lt;/tr>
 &lt;/thead>
 &lt;tbody>
 &lt;tr>
 &lt;td>gRPC&lt;/td>
 &lt;td>内部服务调用&lt;/td>
 &lt;td>高性能、强类型&lt;/td>
 &lt;td>调试不如 REST 方便&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>REST&lt;/td>
 &lt;td>外部 API&lt;/td>
 &lt;td>通用、易理解&lt;/td>
 &lt;td>性能较低&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>消息队列&lt;/td>
 &lt;td>异步解耦&lt;/td>
 &lt;td>削峰、解耦&lt;/td>
 &lt;td>复杂度增加&lt;/td>
 &lt;/tr>
 &lt;/tbody>
&lt;/table>
&lt;h2 id="关键设计原则">关键设计原则&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>幂等性&lt;/strong>：所有写操作都应该是幂等的&lt;/li>
&lt;li>&lt;strong>超时与重试&lt;/strong>：设置合理的超时，使用指数退避重试&lt;/li>
&lt;li>&lt;strong>熔断降级&lt;/strong>：防止级联故障&lt;/li>
&lt;li>&lt;strong>可观测性&lt;/strong>：日志、指标、链路追踪三者缺一不可&lt;/li>
&lt;/ol>
&lt;h2 id="总结">总结&lt;/h2>
&lt;p>分布式系统没有银弹。好的系统设计来自对业务场景的深入理解和对技术取舍的清晰认识。&lt;/p></description></item></channel></rss>