0

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.

  • If you intend to query the DB directly from the client, you will likely have security issues, since client-side validation is not reliable. To avoid them, you could create stored procedures for clients, where all the validation will be performed, and have no other access points for the DB for clients. – superM Apr 13 '13 at 18:45
  • @superM What do you mean by stored procedures for the client, do you mean some data validation code on the client side or something else? – Kartik Anand Apr 14 '13 at 6:08
  • I mean you can create stored procedures inside the MySQL database, and make them accessible from the client. All the validation can be done inside these stored procedures. – superM Apr 14 '13 at 14:42
2

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.

0

The benefit of having client.py connect to port 3306 directly is you don't need to write (and debug) any JSON marshaling code. And you won't need to deploy and maintain instances of server.py. Keep it simple, implement, and write down some timing measurements.

You didn't describe latency or throughput requirements for your application. Number of hosts running client.py matters. Speed of light delay between client and server matters. DB connection pooling might prove useful. Implement the simplest thing that could possibly work, take measurements, and iterate from there.

  • I've added some edits – Kartik Anand Apr 13 '13 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.