The video owner has disabled playback on external websites.

This video is no longer available on YouTube.

This video cannot be played right now.

Watch on YouTube

AI 학습 도구 잠금 해제

가입하여 모든 동영상에서 더 빠르게 학습할 수 있는 강력한 도구를 이용하세요.

장면 설명 표현 찾기 플래시카드 복습 섀도잉 연습 되말하기
무료 회원가입
영어 24:40 Science & Tech

How to Tell If Your Code Is Actually Production-Ready

Late Night with Seth Meyers · 40,235 조회수 · 추가됨 1개월 전

자막 (571 세그먼트)

00:00

Here's an example of a simple fast API

00:02

app that has a single endpoint convert

00:06

and that converts from one currency to

00:08

another. This is just some hard-coded

00:10

rate here. Uh it gets raised from that

00:13

dictionary and then computes the

00:15

conversion. And this actually works. I

00:17

can send a call request to this API and

00:20

I get the results that I want. But is

00:23

this production ready? Well, not really.

00:26

So, I'm going to take this service that

00:28

just works and upgrade it step by step

00:31

into something you can actually deploy

00:33

and rely on in production. And along the

00:36

way, I'm going to talk about things like

00:38

validation, error handling, monitoring,

00:40

deployment, and other things that are

00:42

important when you want production ready

00:45

code. So, let's dive in. Before I start

00:47

working on the code, what does

00:48

production ready actually mean? I mean,

00:51

there's no fixed definition of what that

00:54

is. It can mean different things for

00:56

different types of applications. It

00:58

depends on what is more important.

00:59

Perhaps security is a key issue for you

01:02

because it's a public API or something.

01:04

Or perhaps you are thinking more about

01:06

scalability and you expect this to be

01:08

used by millions of people. Or perhaps

01:12

you really want this to be robust and

01:15

make sure that it absolutely never

01:17

crashes. In any case, production ready

01:19

doesn't mean it works on my machine. And

01:21

to me typically production ready code

01:24

means that it works reliably in

01:26

realworld conditions whatever those

01:28

conditions are. So it means that at the

01:31

core it needs to be observable. It needs

01:33

to be reasonably secure. It needs to be

01:36

maintainable right you need to be able

01:38

to work on it and reasonably resilient.

01:41

Now I start with this very naive uh fast

01:44

API route but uh it only supports

01:47

hard-coded uh conversion. There's no

01:50

validation whatsoever. So, let's improve

01:52

this step by step. Now, before I start,

01:55

if you want to learn more about how to

01:56

design a piece of software from scratch,

01:58

I have a free guide for you. You can get

02:00

this at iron.code/design

02:02

guide. This contains the seven steps I

02:04

take when I design new software and

02:06

hopefully it helps you avoid some of the

02:08

mistakes that I made in the past.

02:09

Iron/design guide. The link is also in

02:12

the description of this video. Now, the

02:14

first step that we're going to take is

02:16

looking at the data that we actually

02:19

expect. So even before you think about

02:21

validation, you have to make sure that

02:23

the data that your app works with is

02:25

actually appropriate. And in this case,

02:28

we're passing a from and two currencies

02:30

as a string, which well makes sense. But

02:33

as you can see, the amount is in float.

02:35

And floats are actually kind of

02:37

dangerous for uh currency handling

02:39

because they're not very precise. So

02:41

it's better to use something like the

02:43

decimal type for amounts and rates. So

02:46

what we're going to do as a first step

02:48

is to fix that.

02:51

So, I'm going to import the decimal

02:54

type. And that means we're going to need

02:56

to make some changes here and here as

02:58

well. So, first I'm going to turn these

03:01

conversion rates into decimal values

03:04

like so.

03:06

Simply going to copy paste this. Now,

03:10

normally I would use AI to edit this

03:12

stuff for me, but I'm not doing that on

03:14

purpose so it's a bit easier for you to

03:16

follow in the video. So now my rates are

03:19

in decimal which is great. I can also

03:21

turn my amount in decimal as well. And

03:24

now let's see what happens when we do

03:26

this conversion. So this still works in

03:29

exactly the same way except now our

03:31

types are much safer. So like I said

03:34

that's something you need to do before

03:35

you even think about uh validation. Make

03:38

sure that your types are appropriate. So

03:41

next step is validating the input. So we

03:43

don't want to be able to send like weird

03:46

stuff to our API. So you need to add

03:49

checks for that. And actually fast API

03:51

which is the library that I'm using here

03:53

has support for doing this via paidantic

03:56

which makes this really easy. In order

03:58

to do that I'm going to import the query

04:01

type from fast API and then we can use

04:03

that to put some guard lines on these

04:05

types. For example, from currency is a

04:07

string. But we can make sure

04:11

that this string has let's say a minimum

04:14

length of three.

04:17

And we can also give it a maximum length

04:20

of three. So we are always sure that

04:22

currencies have an exact length of

04:25

three. And we can do the same thing for

04:27

the two currency like so. And for the

04:31

decimal amounts we can also supply a

04:34

query

04:37

where let's say we want to have

전체 자막은 비디오 플레이어에서 이용 가능

연습 문제로 학습하기

이 동영상에서 어휘, 문법, 이해력 연습 문제를 만드세요

어휘 및 문법 이해력 퀴즈 IELTS 시험 쓰기 연습
회원가입해서 연습하기
아직 댓글이 없습니다. 첫 번째로 생각을 공유하세요!

가입하고 모든 기능 잠금 해제

진행 상황 추적, 단어 저장, 연습 문제 풀기

무료로 언어 학습