代码字体mono_如何构建代码存储库:Multi,Mono或Organic?

代码字体mono

by Chetan Sharma

由Chetan Sharma

如何构建代码存储库:Multi,Mono或Organic? (How to Structure Code Repositories: Multi, Mono, or Organic?)

The newest debate in town is whether you should keep your services in a single repository or multiple small repositories.

城里最新的争论是您应该将服务保存在单个存储库还是多个小型存储库中。

The idea of multiple small repositories is that code for each of your app’s micro service is kept in a repository of its own. With a mono-repo, you keep the all the code in a single repository and deploy the code as microservices.

多个小型存储库的想法是,每个应用程序微服务的代码都保存在自己的存储库中。 使用mono-repo,您​​可以将所有代码保存在单个存储库中,并将代码部署为微服务。

So which should you use? Being too rigid about any one approach — without considering the purpose and uses of each approach — can lead to negative outcomes in the long run. If you’re aware of when to use each, it can increase your productivity and improve your project.

那么您应该使用哪个呢? 从长远来看,对任何一种方法过于僵化(不考虑每种方法的目的和用途)都可能导致负面结果。 如果您知道何时使用它们,则可以提高生产率并改善项目。

要改变规则,我们首先需要了解它们为什么存在。 (To bend the rules, we need to first understand why they exist.)

A common recommendation is to have an independent repository for every app/service. But why? Because, by having one repository for each micro-service, we gain:

常见的建议是为每个应用程序/服务都有一个独立的存储库。 但为什么? 因为,通过为每个微服务拥有一个存储库,我们可以获得:

  • Freedom to write code differently and independently of all other services.

    自由编写代码不同,独立于其他所有服务。

  • Velocity in making code changes while fixing bugs, making updates, testing and deploying. Since changes only have to be tested in a single repository, deployment of the code is faster and more reliable.

    速度修改代码,而修正错误,进行更新,测试和部署。 由于更改只需在单个存储库中进行测试,因此代码的部署更加快捷,可靠。

  • Separation of code as independent units, which prevents bug leakages and performance bottlenecks between services.

    将代码分隔为独立的单元,从而防止错误泄漏和服务之间的性能瓶颈。

  • Clear ownership of each repository and service, which is especially helpful for large teams.

    明确每个存储库和服务的所有权 ,这对于大型团队尤其有用。

但是,为什么会出现单一回购协议的需求? (But why did the need for mono-repos arise?)

Clearly, the multi-repo approach has its benefits. But it also comes with its own challenges, especially in projects with a large number of microservices that use the same frameworks, language, tech stacks etc.

显然,多重回购方法有其好处。 但这也带来了自己的挑战,特别是在使用相同框架,语言,技术堆栈等具有大量微服务的项目中。

A few of these challenges are:

这些挑战包括:

  • Enforcing standards and best practices across all repositories. With a multi-repo, changes in code standards and best practices need to be replicated across repositories. With a mono-repo, all the changes can be done in one place.

    在所有存储库中执行标准和最佳实践 。 对于多仓库,需要在存储库之间复制代码标准和最佳实践的更改。 使用单仓库,所有更改都可以在一个地方完成。

  • The effort of maintaining shared or common components. Security patches, version upgrades and bug fixes involve making sure that these changes are made across all repositories and that they work seamlessly everywhere. (On a side note, the repeated code in each service also bloats its size.) In a mono-repo, we can make updates in one place, saving both time and headaches.

    维护共享或通用组件的努力。 安全补丁,版本升级和错误修复涉及确保在所有存储库中进行这些更改,并且确保它们在任何地方都可以无缝运行。 (顺便说一句,每个服务中重复的代码也增加了它的大小。)在单一仓库中,我们可以在一个地方进行更新,既省时又省力。

  • End-to-end testing in tandem with closely related or dependent services right from the developer’s machine. By having all the code in one place, we ease the process of starting up all the related services and running end-to-end tests.

    直接从开发人员的机器进行与紧密相关或依存服务的端到端测试 。 通过将所有代码放在一个位置,我们简化了启动所有相关服务和运行端到端测试的过程。

  • On-premise deployments of code for other businesses. By deploying a mono-repo as microservices, we save time and reduce the redundant effort of bootstrapping each repository.

    用于其他业务的本地代码部署 。 通过将单存储库部署为微服务,我们可以节省时间并减少引导每个存储库的冗余工作。

Clearly, there are advantages and disadvantages to both approaches, and each approach will have its own benefits under different circumstances.

显然,这两种方法都有优点和缺点,并且每种方法在不同的情况下都会有自己的优点。

Therefore, we have adopted the approach of remaining flexible and using both multi-repos and mono-repos, but only after completely understanding why we have chosen to use each for each service. This has led us to have multiple repos containing several microservices, segregated in a way that has made:

因此,我们采取了保持灵活性的方法,并同时使用了多仓库和单仓库,但要完全理解为什么我们选择为每种服务使用每种仓库。 这导致我们有多个包含多个微服务的存储库,这些存储库以如下方式隔离:

  • Maintenance and updates both easy and fast.

    维护和更新既简便又快速。
  • Locating the code to debug or change much more structured.

    查找要调试或更改的代码要结构化得多。
  • Onboarding new teammates easier.

    新队友的入职更加轻松。

我们如何决定使用哪种类型的存储库 (How we decide what type of repository to use)

The following considerations have helped us decide when to use mono-repos vs. multi-repos.

以下考虑因素帮助我们决定了何时使用单存储库和多存储库。

1.考虑将用作服务基础的代码。 (1. Think about the code that will serve as the foundation of the service.)

Begin by identifying any similarities in code, maintenance, and updates. If multiple repositories have identical code, it would be better to club them in a single repository.

首先确定代码,维护和更新中的任何相似之处。 如果多个存储库具有相同的代码,最好将它们合并在一个存储库中。

The freedom to write code differently and independently in a service is one of the benefits of multiple small repositories. But often services will have a lot of identical scaffolds if they use the same language, framework, logging, bootstrap scripts, middle-wares, etc. Reusing these shared scaffolds saves time.

在服务中以不同方式独立地编写代码的自由是多个小型存储库的好处之一。 但是,如果服务使用相同的语言,框架,日志记录,引导脚本,中间件等,则它们通常会有很多相同的支架。重用这些共享的支架可以节省时间。

For example, Collect — our primary data collection tool — has multiple micro-services built on an identical framework. These services are built on Node.js, Express and Parse Server. They share a lot of libraries like Winston, Mongoose and other third-party integrations. Earlier, when each of these services had a repository of its own, updating or fixing a bug in any of these shared modules meant updating and testing each repository separately. This was slow and cumbersome.

例如, 收集 (我们的主要数据收集工具)具有在相同框架上构建的多个微服务。 这些服务基于Node.js , Express和Parse Server构建。 他们共享许多库,例如Winston , Mongoose和其他第三方集成。 早先,当这些服务中的每一个都有自己的存储库时,更新或修复这些共享模块中的任何一个中的错误就意味着分别更新和测试每个存储库。 这既缓慢又麻烦。

However, when we clubbed them together in a mono-repo, testing and updating the shared modules became easier and faster. Applying security patches and enforcing standards became easier since developers can do all the changes in once place.

但是,当我们将它们组合成一个单体仓库时,测试和更新共享模块变得更加容易和快捷。 由于开发人员可以一次完成所有更改,因此应用安全补丁和执行标准变得更加容易。

The potential risk of a mono-repo is that a developer can reuse code originally written for an unrelated module. When the two modules share code, then change in this common code can lead to bugs. If these bugs go unchecked, they can affect the CI/CD (Continuous Integration and Delivery) pipelines of unrelated micro-services. To avoid such issues, it is important to have a strong testing suite in place.

单一仓库的潜在风险是开发人员可以重用最初为无关模块编写的代码。 当两个模块共享代码时,更改此公共代码可能会导致错误。 如果不检查这些错误,它们可能会影响不相关的微服务的CI / CD(连续集成和交付)管道。 为避免此类问题,重要的是要有一个强大的测试套件。

2.检查是否有与其余模块完全不同的模块。 (2. Check whether you have any modules that are very distinct from the rest.)

Are you developing a module that demands a very different technology, language, framework or persistence? Then separating it out into a separate repository will be better.

您是否正在开发一个需要非常不同的技术,语言,框架或持久性的模块? 然后将其分离到一个单独的存储库中会更好。

In Collect, there are services that handle processing of events in bulk. They maintain queues, execute custom scripts and have a completely different error-handling mechanism. These services are written in Python, and quite often they need to do CPU-intensive tasks.

在“收集”中,有一些服务可以批量处理事件。 它们维护队列,执行自定义脚本,并具有完全不同的错误处理机制。 这些服务是用Python编写的,并且经常需要执行CPU密集型任务。

So when we were thinking about restructuring the code for Collect, keeping these services in a separate repo came across as self evident. These services were very different from Collect’s main repository (described above). While the main repository was for user-facing requests, this repo was all about background tasks and executions. Also, the change management in these services was going to be different and isolated from the main repository.

因此,当我们考虑重组Collect的代码时,很明显地将这些服务保存在单独的存储库中。 这些服务与Collect的主要存储库(如上所述)非常不同。 虽然主要存储库是用于面向用户的请求,但此回购全是关于后台任务和执行的。 而且,这些服务中的变更管理将有所不同,并且与主存储库隔离。

Thinking about the code maintenance and how it is going to evolve over time led us to club these services in a separate repository. By doing that, we were able to put up a completely different change management system, which turned out to be very helpful and more productive.

考虑到代码维护及其随着时间的发展,我们将这些服务合并到一个单独的存储库中。 通过这样做,我们能够建立一个完全不同的变更管理系统,事实证明该系统非常有用,而且效率更高。

3.考虑不确定性,因此要考虑服务可能经历的更改频率。 (3. Consider the uncertainty and therefore the frequency of changes a service might go through.)

When you start working on something that is highly uncertain (either in terms of the scope of the problem or the implementation itself), then having a different repository can give you with the velocity and freedom you need to test things.

当您开始进行高度不确定的事情(无论是问题的范围还是实现本身)时,拥有不同的存储库可以为您提供测试事物的速度和自由度。

For example, say that you want to test a new way of processing images to identify objects. You want to dabble with machine learning, but you are still unsure how it will evolve or if the problem statement will change dramatically. In this case, it would be clearly better to have a separate repository and then get to a point of certainty. Conversely, if you think that the API has reached stability and will remain unchanged for a large amount of time, you can take a call to merge it with one of your main repositories.

例如,假设您要测试一种处理图像以识别对象的新方法。 您想涉足机器学习,但仍不确定它会如何发展或问题陈述是否会发生巨大变化。 在这种情况下,最好有一个单独的存储库,然后再确定一点。 相反,如果您认为该API已达到稳定性,并且会在相当长的时间内保持不变,则可以调用将其与您的主要存储库之一合并。

The blog was originally published on blog.socialcops.com. The above is how we handle our repository decisions. I hope it can help you in thinking from first principles if you approach this problem. Do subscribe to our newsletter for more updates from SocialCops Engineering and Data Science Team.

该博客最初发布在blog.socialcops.com上。 以上是我们处理存储库决策的方式。 我希望,如果您解决此问题,它可以帮助您从首要原则出发进行思考。 请订阅我们的新闻通讯,以获取SocialCops工程和数据科学团队的更多更新。

翻译自: https://www.freecodecamp.org/news/how-to-structure-code-repositories-multi-mono-or-organic-eda67b397d38/

代码字体mono

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/393069.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

leetcode1424. 对角线遍历 II(排序)

给你一个列表 nums ,里面每一个元素都是一个整数列表。请你依照下面各图的规则,按顺序返回 nums 中对角线上的整数。 示例 1: 输入:nums [[1,2,3],[4,5,6],[7,8,9]] 输出:[1,4,2,7,5,3,8,6,9] 代码 class Solution …

DaVinci各版本安装指南

链接: https://pan.baidu.com/s/1g1kaXZxcw-etsJENiW2IUQ?pwd0531 ​ #2024版 1.鼠标右击【DaVinci_Resolve_Studio_18.5(64bit)】压缩包(win11及以上系统需先点击“显示更多选项”)【解压到 DaVinci_Resolve_Studio_18.5(64bit)】。 2.打开解压后的文…

使用 Servlet 读取表单数据

Technorati 标签: servlet;java 一、概述 Servlet 有一个比较好的功能就是可以自动处理表单提交的数据。我们只需要调用HttpServletRequest#getParameter(String name),就可以获得指定参数的值(String),注意此方法是大小写敏感的。…

linux文档权限

1、登录 root 用户:su - mac一开始进入创建的用户是具有管理员权限的用户,但是密码却不是进入 root 用户的密码,可以使用 sudo su - 免密进入 root 用户。 2、退出 root 用户:exit 3、列出档案(包括隐藏的档案&#xf…

小程序 仿麦当劳_手机上的麦当劳和星巴克:为什么现在首先使用移动应用程序...

小程序 仿麦当劳by James Hsu由徐H 手机上的麦当劳和星巴克:为什么现在首先使用移动应用程序 (McDonald’s and Starbucks on Your Phone: Why Mobile Apps Are Now First on the Menu) One Friday this July, I got excited about McDonalds. So excited that I s…

MyLinkedList

/*** 节点类* author JP* */ class Node {Object value;//节点元素值Node pre;//上一个节点Node next;//下一个节点public Node(Object value) {this.value value;} }/*** 链表类* author JP**/ public class MyLinkedList {Node cur;//目前指向的节点Node head;//头结点Node …

linux开启ping服务,Linux 云服务器禁止和开启Ping

原标题:Linux 云服务器禁止和开启Ping在使用Linux服务器的时候,一般系统默认是开启ping的,比如我们可以ping测试网络的延迟质量。当然也有部分服务商是可以通过安全组设置禁止ping的,我们可以设置安全组对应项目开启或禁止ping&am…

leetcode1432. 改变一个整数能得到的最大差值(贪心)

给你一个整数 num 。你可以对它进行如下步骤恰好 两次 &#xff1a; 选择一个数字 x (0 < x < 9). 选择另一个数字 y (0 < y < 9) 。数字 y 可以等于 x 。 将 num 中所有出现 x 的数位都用 y 替换。 得到的新的整数 不能 有前导 0 &#xff0c;得到的新整数也 不能…

oracle之 Oracle归档日志管理

在Oracle中&#xff0c;数据一般是存放在数据文件中&#xff0c;不过数据库与Oracle最大的区别之一就是数据库可以在数据出错的时候进行恢复。这个也就是我们常见的Oracle中的重做日志(REDO FILE)的功能了。在重做日志分成2部分&#xff0c;一个是在线重做日志文件&#xff0c;…

linux 安装rmp服务,Linux LAMP服务的rpm包安装与配置

1.apache(httpd) 所在光盘装包apr-xxx.rpm (二)postgresql-libs-xxx.rpm (二)apr-util-xxx.rpm (二)http-xxx.rpm (二)2.mysql (二)装包perl-DBI-xxx.rpm (二)mysql-xxx.rpm (二)3.mysqlserver装包perl-DBD-mysql-xxx.rpm (二)mysql-server-xxx.rpm (二)4.PHP装包gmp-xxx.rpm (…

红外感应模块+蜂鸣器实现简易报警(转)

拿到了一个红外感应模块HC-SR501&#xff0c;于是就用它和蜂鸣器简单试验了下。主要是试验一下这个红外感应模块的功能&#xff0c;所以代码也写的很随便啦&#xff0c;逻辑上也欠考虑。实现基本功能&#xff1a;运行脚本后&#xff0c;感应模块每隔一定时间检测&#xff0c;如…

leetcode51. N 皇后(回溯算法)

n 皇后问题研究的是如何将 n 个皇后放置在 nn 的棋盘上&#xff0c;并且使皇后彼此之间不能相互攻击。 上图为 8 皇后问题的一种解法。 给定一个整数 n&#xff0c;返回所有不同的 n 皇后问题的解决方案。 每一种解法包含一个明确的 n 皇后问题的棋子放置方案&#xff0c;该方案…

ubuntu下python的错误

ubuntu python 2.7 python test.py *.py permission denied chmod x *.py 转载于:https://www.cnblogs.com/gisalameda/p/11086624.html

kotlin半生对象_如何在Kotlin中使用Actor实现对象池

kotlin半生对象by osha1由osha1 如何在Kotlin中使用Actor实现对象池 (How to implement an Object-Pool with an Actor in Kotlin) We use object pool in jasync-sql to manage connections to the database. In this post, I will share how it is done in a performant, lo…

linux运行apktool签名,解决Linux中使用ApkTool遇到问题

8种机械键盘轴体对比本人程序员&#xff0c;要买一个写代码的键盘&#xff0c;请问红轴和茶轴怎么选&#xff1f;遇到问题在Linux中使用IntelliDroid工具时&#xff0c;按要求配置好环境之后&#xff0c;始终无法成功运行该工具内部的ApkTool&#xff0c;导致后续的安卓静态分析…

python 脚本学习(二)

task1&#xff1a; 在一个文件中&#xff0c;单词之间使用空格、分号、逗号或者句号分隔&#xff0c;请提取全部单词。 代码实例&#xff1a; 1234567891011#!/usr/local/python27/bin/python2.7import sys import re words [] with open(sys.argv[1]) as f: for line in f: #…

2.2 Consumer API官网剖析(博主推荐)

不多说&#xff0c;直接上干货&#xff01; 一切来源于官网 http://kafka.apache.org/documentation/ 2.2 Consumer API 2.2、消费者API 随着0.9.0版本&#xff0c;我们已经增加了一个新的Java消费者替换我们现有的基于zookeeper的高级和低级消费者。这个客户端还是测试版的质量…

leetcode1053. 交换一次的先前排列(贪心算法)

给你一个正整数的数组 A&#xff08;其中的元素不一定完全不同&#xff09;&#xff0c;请你返回可在 一次交换&#xff08;交换两数字 A[i] 和 A[j] 的位置&#xff09;后得到的、按字典序排列小于 A 的最大可能排列。 如果无法这么操作&#xff0c;就请返回原数组。 示例 1&a…

mybatis-generator-gui如何打包成exe

快速阅读&#xff1a; ​ 用wix和inno setup把mybatis-generator-gui 打包成exe和安装文件。 以后使用的时候方便&#xff0c;不用每次打开eclipse运行。 使用inno setup 5 和wix 3.11 基于mybatis generator开发一款界面工具, 非常容易及快速生成Mybatis的Java POJO文件及数据…

分步表单如何实现 html_HTML表单入门的分步指南

分步表单如何实现 htmlby Abhishek Jakhar通过阿比舍克贾卡(Abhishek Jakhar) HTML表单入门的分步指南 (A step-by-step guide to getting started with HTML forms) 总览 (Overview) HTML forms are required when you want to collect some data from the person who visits…