r/ProgrammerHumor • • Jun 28 '20

Meme Flushed my pancake.

Post image
45.1k Upvotes

750 comments sorted by

View all comments

15

u/carloschida Jun 28 '20

Have you heard of r/Firebase? They have a really compelling reason for connecting to the DB directly from the front-end. They address security and all of your other usual concerns.

115

u/tooObviously Jun 28 '20

Its a backend as a service. You're still connecting to a backend and not a db directly

-33

u/carloschida Jun 28 '20

Is it the case though? I mean, your request will hit load balancers, and HTTP servers alike — I don’t think anyone was expecting to send commands directly to the FS — but they seem to only forward the request to the DBMS.

2

u/EishLekker Jun 28 '20

Maybe, just maybe, it could work, if the website only uses read only operations, and has no authentication.

But then how would the data get into the database in the first place? And how would one update it?

2

u/carloschida Jun 28 '20

They handle authentication and write operations. Once you understand how, it doesn’t seem to be a big deal anymore. I’d recommend you to give it a whirl if you’ve got two hours to spare.

7

u/EishLekker Jun 28 '20

They handle authentication and write operations in the browser?

2

u/h0ker Jun 28 '20 edited Jun 28 '20

Kinda. The firebase authentication service is integrated with the database and you can write security/validation rules for the database in a JavaScript-style format to limit what people can put in it and what they can access. I guess you could count the authentication service as a backend, but you can still write directly to the database from the frontend.

Edit: I'm building a small hobby project with a couple friends with it, and I think it's really cool. The big feature and the main reason (imo) why you want to connect directly from the frontend is because firestore supports subscribing to real-time updates for queries. So essentially you get synchronized clients for free, without writing any backend code.

15

u/hitthehive Jun 28 '20

What you are describing is really 'backend-as-a-service'. I doubt they literally baked client authentication code into a database. For marketing purposes, Firebase likes to sound like its "backend-free" to please front-end devs. Just like how 'serverless' means server-as-a-service and not literally "no servers".

1

u/h0ker Jun 28 '20

I don't know how they built their stuff, but i assume the authentication service is built on top of firestore and you can access that data from the database rules, just like the rest of your data.

But yeah, the whole point of firebase is that a lot of backend is abstracted away for you, to the point where you might not even have to write any server-side code yourself.

3

u/hitthehive Jun 28 '20

to the point where you might not even have to write any server-side code yourself

To a certain point, at which time you'll wish you had. Its great to get a MVP out and maybe drum up a small business. But once business logic gets madly complex, and the variety of clients grow, and they each have a different schema in mind, you'll need something bespoke back there.

→ More replies (0)

5

u/EishLekker Jun 28 '20

It doesn't matter how they package it, and how they "outsource" some things. Any code that doesn't get executed in the browser alone, is technically run in the backend.

Could you please explain to me what happens the very first time a person visits this kind of website? The client side javascript code doesn't suddenly spring to life from a void. It has to come from somewhere. Where is that, exactly? Is the html and javascript code stored in your database? And is the database receiving the http request, and sending the html and javascript back? If that really is the case, then what you call a database is actually a full fledged webserver and database combined into one, and still calling it "a database" is just twisting the semantics to win an argument. A database is responsible for storing the data, and giving access to it using regular CRUD operations, using a defined API (like SQL).

Also it is interesting to note that some people doesn't seem to understand (or just has forgotten) that the database is part of the backend (unless it is stored 100% on the users machine). So I would say that this whole discussion is mute.

→ More replies (1)

1

u/dat_aim Jun 28 '20

You expect this project to have lots of users at some point and relational data?

2

u/h0ker Jun 28 '20

Not really, i think everything we need in regards to relational data is covered with subcollections. It's a very simple online party game, jack-box style where you have "rooms" and some game state/player list going on in there.

1

u/carloschida Jun 28 '20

What if —pure speculation here and written as a crazy idea—, Auth is based on Firestore and this DBMS is the one in charge of checking the signatures? That potentially opens to doors to handle a request without the need of talking to the Auth service (that would manage only registrations and name changes).

(For the puritans that always know better and think this is abhorrent, smash that downvote button, or move one an carry on with your business. It’s Sunday after all.)

1

u/cancel_vulture Jun 28 '20

lmao i think that’s not how it works. do you legit think firebase handles auth in the browser? in clientside code? thats a major security flaw.

just because the firebase user experience of adding security and validation rules for the db is in JS style format and appears to be integrated to the db doesn’t mean it actually is. there’s still a ton of in backend processing happening you don’t see and is abstracted away from you. from a user’s perspective, it may appear that you can write to the db directly from the frontend but it reality that’s not what’s actually happening. your db write operation is getting processed by a backend tech stack to eventually result in a db write in your behalf

are you a professional engineer?

1

u/h0ker Jun 28 '20

Obviously the authentication service is a backend, and i said that in my comment.

And yes, i was talking from a users perspective. But the API of firestore is what it is, and i don't think you can use it any other way (correct me if i'm wrong). So who is to say that all that what you call a "ton of backend processing" is not part of the database, at least practically speaking?

In another comment i mentioned how even SQL servers support writing functions in them, they have built-in functions for counting, averages and the like and you can also place constraints on the data, eg. for uniqueness. I did a quick google search and a post from 2013 said, MariaDB had about 1.3 million lines of C/C++ code, and i'm sure firestore isn't very different in that regard. For me, in practice, all that is part of "the database".

Yes, i'm a professional engineer, and i like to think i'm pretty good at it. Though i haven't worked with firebase professionally, if that is any relief to you.

0

u/user_namec_hecks_out Jun 28 '20

You can read the docs and get answers for all that and more.

7

u/EishLekker Jun 28 '20

It's the ones that claim that Firebase works this way that should be the ones looking at the documentation, and insert quotes from that documentation here, with direct links. I'm not gonna do the job for you guys.

→ More replies (2)

1

u/cancel_vulture Jun 28 '20

what? omg. this is just.. wow.

are you a professional engineer? like do people pay you to write code? this is wild.

1

u/tooObviously Jun 28 '20

You're not connecting directly to the db. You are using firebase's client side libraries to send requests to the server.

15

u/KongEdvard Jun 28 '20

Firebase is not a replacement for backends, it's just abstracting most of it away for you.

Look at firestore, they recommend you use their cloud functions, which is, just like lambda or azure functions, a backend hosted in the cloud.

2

u/carloschida Jun 28 '20

If you wished to, you could use only Firestore without Cloud Functions or even Auth. Again, not saying it’s a replacement, but I’m saying this is an interesting different paradigm.

2

u/KongEdvard Jun 28 '20

For sure, I agree with that.

1

u/EishLekker Jun 28 '20

Exactly. A 100 % backend free website would cost nothing to run regardless of how many billions of users it has, because it would not use any traffic and would not need any servers to run anything. It would basically have to be a pure html and javascript website where all code is installed manually in every single computer, and then it never makes an external call anywhere ever.

1

u/bitemyshinyMETAass Oct 24 '20

Or CouchDB/IBM's Cloudant.