Database Networking – Use Client or Server to Access Database

databasenetworking

I' creating a client server application in which I need to update a particular database. I'm using python with MySQL. There are two options:

I use a client.py and server.py, the client.py can send data packed into JSON to the server, the server.py will handle the database and send query data back in the form of JSON.

The second option is that there is no server.py file, instead the client accesses databases and queries directly with the MySQL server.

Is there any benefits to using one method to another?

EDIT:

There can be atmost about 100 clients and they will be sending data throught the day with a delay of about about 20 seconds.

Best Answer

What you are asking about here is the classic 2-tier vs 3-tier (or n-tier) decision.

First off, there's no inherently correct answer. Which you go with really depends on what your goals are.

In a client-server setup, you connect directly to the database from the client. The benefit of this is it is a simple setup. The downside is you are essentially giving direct access to the database to anyone running the client (which includes database connection info). You also potentially may need to make sure all the proper database drivers are installed on the machines running the client (this may not be an issue for python/mysql programs).

In a 3-tier system, the clients communcate with an application server, and that application server is the only program that will interact with the database server. One benefit is security - the database can be safely out of reach of the clients. And you dont have to worry about configuring database drivers on each client. You then also have the application server functionality if you expand to web and mobile applications. The downside of course is that its more work to set up - you need to make/implement the application server (which can, btw, just be a web server).

tl/dr... read up on 2-tier vs 3-tier designs.