简体   繁体   English

更改 API 时避免停机的最佳实践?

[英]Best practices for avoiding downtime when making changes to the API?

I am making a React-Django application which I have deployed using Vercel.我正在制作一个使用 Vercel 部署的 React-Django 应用程序。

My concern is that sometimes I will need to make changes to the API and I am not sure how to handle that without causing downtime in production.我担心的是,有时我需要对 API 进行更改,但我不确定如何在不导致生产停机的情况下进行处理。

Say for example that I change an endpoint's payload (for example, I might change the variable names or its structure).例如,我更改了端点的有效负载(例如,我可能会更改变量名称或其结构)。 Say I reflect those changes in the frontend, making sure that the frontend can accept the new payload.假设我在前端反映了这些变化,确保前端可以接受新的有效负载。

Now, if I push the new API to live and the front-end has not been pushed to live yet, the (old) front-end will make get a payload it won't be able to work with and thus the app will crash.现在,如果我将新的 API 推送到 live 并且前端还没有推送到 live ,(旧的)前端将获取一个它无法使用的有效负载,因此应用程序将崩溃. If on the other hand I push the new front-end to live but the new API is not live yet, the (new) front-end will get the old payload's structure which it's no longer able to work with.另一方面,如果我推动新的前端上线但新的 API 尚未上线,则(新)前端将获得不再能够使用的旧有效负载的结构。 The app will crash in this case too.在这种情况下,应用程序也会崩溃。

How can I ensure that when I make changes to the API and to the frontend I can do so whilst also avoiding any downtime?如何确保当我对 API 和前端进行更改时,我可以这样做,同时避免任何停机时间? What are the best practices to do this?执行此操作的最佳做法是什么?

(As a reminder, the app has a React frontend and a Django backend and is deployed through Vercel) (提醒一下,该应用程序有一个 React 前端和一个 Django 后端,并通过 Vercel 部署)

Any help is appreciated, thank you!任何帮助表示赞赏,谢谢!

In a project I worked on before I added a notification queue broadcasting a notification to logged in users saying that we're having maintenance and I block any request and displaying a toast and I block the login for some minutes synchronizing with my team to build and post the front updates.在我工作的一个项目中,我添加了一个通知队列,向登录的用户广播一个通知,说我们正在进行维护,我阻止任何请求并显示敬酒,我阻止登录几分钟与我的团队同步构建和发布前面的更新。

I used react as front Symfony php as API and I used Mercury as Messaging queue in your case you can use sockets.我使用 react 作为前面 Symfony php 作为 API 我使用 Mercury 作为消息队列在你的情况下你可以使用 API

Or if you're sure that your users won't use your app late at night synchronize with your team to make updates late at night but it's risky if someone use it so that's why I notify my users for some minutes或者,如果您确定您的用户不会在深夜使用您的应用程序,请与您的团队同步以在深夜进行更新,但如果有人使用它是有风险的,所以这就是为什么我会通知我的用户几分钟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM