Are mutliple database calls really significant with a network call for a web API?

At one of my employers, we worked on a REST (but it also applies to SOAP) API. The client, which is the application UI, would make calls over the web (LAN in typical production deployments) to the API. The API would make calls to the database.
One theme that recurs in our discussions is performance: some people on the team believe that you should not have multiple database calls (usually reads) from a single API call because of performance; you should optimize them so that each API call has only
(exactly) one database call.
But is that really important? Consider that the UI has to make a network call to the API; that's pretty big (order of magnitude of milliseconds). Databases are optimized to keep things in memory and execute reads very, very quickly (eg. SQL Server loads and
keeps everything in RAM and consumes almost all your free RAM if it can).
TLDR: Is it really significant to worry about multiple database calls when we are already making a network call over the LAN? If so, why?
To be clear, I'm talking about order of magnitude -- I know that it depends on specifics (machine hardware, choice of API and DB, etc.) If I have a call that takes O(milliseconds), does optimizing for DB calls that take an order of magnitude less, actually
matter? Or is there more to the problem than this?
Edit: for posterity, I think it's quite ridiculous to make claims that we need to improve performance by combining database calls under these circumstances -- especially
with a lack of profiling. However, it's not my decision whether we do this or not; I want to know what the rationale is behind thinking this is a correct way of optimizing web API calls.

But is that really important? Consider that the UI has to make a network call to the API; that's pretty big (order of magnitude of milliseconds). Databases are optimized to keep things in memory
and execute reads very, very quickly (eg. SQL Server loads and keeps everything in RAM and consumes almost all your free RAM if it can).
The Logic
In theory, you are correct. However, there are a few flaws with this rationale:
From what you stated, it's unclear if you actually tested / profiled your app. In other words, do you actually know that
the network transfers from the app to the API are the slowest component? Because that is intuitive, it is easy to assume that it is. However, when discussing performance, you should never assume. At my employer, I am the performance lead. When I first joined,
people kept talking about CDN's, replication, etc. based on intuition about what the bottlenecks must be. Turns out, our biggest performance problems were poorly performing database queries.
You are saying that because databases are good at retrieving data, that the database is necessarily running at peak performance, is being used optimally, and there is nothing that can be done
to improve it. In other words, databases are designed to be fast, so I should never have to worry about it. Another dangerous line of thinking. That's like saying a car is meant to move quickly, so I don't need to change the oil.
This way of thinking assumes a single process at a time, or put another way, no concurrency. It assumes that one request cannot influence another request's performance. Resources are shared,
such as disk I/O, network bandwidth, connection pools, memory, CPU cycles, etc. Therefore, reducing one database call's use of a shared resource can prevent it from causing other requests to slow down. When I first joined my current employer, management believed
that tuning a 3 second database query was a waste of time. 3 seconds is so little, why waste time on it? Wouldn't we be better off with a CDN or compression or something else? But if I can make a 3 second query run in 1 second, say by adding an index, that
is 2/3 less blocking, 2/3 less time spent occupying a thread, and more importantly, less data read from disk, which means less data flushed out of the in-RAM cache.
The Theory
There is a common conception that software performance is simply about speed.
From a purely speed perspective, you are right. A system is only as fast as its slowest component. If you have profiled your code and found that the Internet is the slowest component, then everything else is obviously not the slowest part.
However, given the above, I hope you can see how resource contention, lack of indexing, poorly written code, etc. can create surprising differences in performance.
The Assumptions
One last thing. You mentioned that a database call should be cheap compared to a network call from the app to the API. But you also mentioned that the app and the API servers are in the same LAN. Therefore, aren't both of them comparable as network calls? In
other words, why are you assuming that the API transfer is orders of magnitude slower than the database transfer when they both have the same available bandwidth? Of course the protocols and data structures are different, I get that, but I dispute the assumption
that they are orders of magnitude different.
Where it gets murkey
This whole question is about "multiple" versus "single" database calls. But it's unclear how many are multiple. Because of what I said above, as a general rule of thumb, I recommend making as few database calls as necessary. But that is
only a rule of thumb.
Here is why:
Databases are great at reading data. They are storage engines. However, your business logic lives in your application. If you make a rule that every API call results in exactly one database call, then your business logic may end up in the database. Maybe that
is ok. A lot of systems do that. But some don't. It's about flexibility.
Sometimes to achieve good decoupling, you want to have 2 database calls separated. For example, perhaps every HTTP request is routed through a generic security filter which validates from the DB that the user has the right access rights. If they do, proceed
to execute the appropriate function for that URL. That function may interact with the database.
Calling the database in a loop. This is why I asked how many is multiple. In the example above, you would have 2 database calls. 2 is fine. 3 may be fine. N is not fine. If you call the database in a loop, you have now made performance linear, which means it
will take longer the more that is in the loop's input. So categorically saying that the API network time is the slowest completely overlooks anomalies like 1% of your traffic taking a long time due to a not-yet-discovered loop that calls the database 10,000
times.
Sometimes there are things your app is better at, like some complex calculations. You may need to read some data from the database, do some calculations, then based on the results, pass a parameter to a second database call (maybe to write some results). If
you combine those into a single call (like a stored procedure) just for the sake of only calling the database once, you have forced yourself to use the database for something which the app server might be better at.
Load balancing: You have 1 database (presumably) and multiple load balanced application servers. Therefore, the more work the app does and the less the database does, the easier it is to scale because it's generally easier to add an app server than setup database
replication. Based on the previous bullet point, it may make sense to run a SQL query, then do all the calculations in the application, which is distributed across multiple servers, and then write the results when finished. This could give better throughput
(even if the overall transaction time is the same).
TL;DR
TLDR: Is it really significant to worry about multiple database calls when we are already making a network call over the LAN? If so, why?
Yes, but only to a certain extent. You should try to minimize the number of database calls when practical, but don't combine calls which have nothing to do with each other just for the sake of combining them. Also, avoid calling the database in a loop at all
costs.

Similar Messages

  • ACS Database Replication over VPN with overlapping Network Addresses

    We currently have two co-locations each situated in different provinces. We have two ACS servers which we want to deploy at each co-location. All our network equipments are behind PIX/ASA devices. Getting them to replicate over the VPN should be easy but in our case we have overlapping Network Addresses at both ends of the tunnels.
    As per Cisco data does not transit a NAT device when the two Cisco Secure ACS servers communicate and a successful database replication can occur only if the secondary ACS server perceives no change in the IP header or content of the data it receives. So that means we will not be able to Implement NAT to achiever this.
    Has any one of you faced this problem of replicating ACS Database over the VPN with overlapping Network Addresses and was anyone able to successfully solve this issue using a work around ?
    All provided info and comments are greatly appreciated.

    I can help with the 3005 setup if you decide to go that route.
    You will need to add 2 network list entries under Configuration>Policy Management>Traffic Management>Network Lists.
    You will need to configure a local and remote address. The local will be one of the public ip's for the site.(Provided by your ISP)The remote will be the device you are connecting to on the other end.
    You will also need to add a Nat Lan to Lan rule under Configuration>Policy Management>Traffic Management>Nat>Lan to Lan.
    Use a static Nat type. The rest will look similar to my example.
    Source(Local address)Translated(Public Ip Address used in the network local list)Remote(Ip address of the device on the other end)
    Now just create an Ipsec lan to lan tunnel. You will need to agree with the ISP on des type and auth type. Use you local and remote networks you created earlier.

  • When I upload my images to the web they are not as vibrant. I am using the Save for the Web feature.

    When I upload my images to the wed they are not as vibrant. I am using the Save for the web feature and my sRGB is checked. I dont know what else to do. HELP!

    We really need to see what you're seeing.
    Can you post links to before and after?

  • I am trying to connect to my Wifi Network. It is a Galaxy Nexus. I am trying to connect to this Hotspot. I have an iMac that works fine with my network but for some reason with this computer I cannot connect.

    So far I have pulled the system configuration file, I have reset safari, I deleted all old passwords from the wifi network in Keychain I restarted both devices. I am at the end here and I cannot get it to work I have an iMac that works fine with my network but for some reason this computer will not connect. It is system wide specifically to my personal hotspot. I can connect fine to any other network (wifi) but just not mine. I have not changed any wifi settings. I have been trying to figure this out. I have a MacBook Pro Late 2006 model running Lion (10.7.5) So any ideas anyone? Please help!

    12. At a WiFi hotspot, you can't get connected.  The most frequent reason is the login screen for the WiFi hotspot is only able to be connected with a single type of browser.  If Safari doesn't work, try Firefox, Chrome, Omniweb, or Opera. 
    From my tip:
    https://discussions.apple.com/docs/DOC-6411

  • IOS8 keypad during phone call not registering with automated phone calls

    Since upgrading to iOS 8, when I call a number that requires a keypad selection to be transferred to the appropriate extension, somehow the automated service does not pick up on my selections.  This happens every time I try to call a business that has an automated service that requires a number selection to be connected to the appropriate extension.  This is an EXTREME INCONVENIENCE when I am trying to reach my children's pediatrician for a serious matter in which I have had to do in the past 2 weeks.  Please fix this Apple!!!!!

    My case with all the notes (6 months worth) has been submitted according to Apple Engineering.
    I would suggest anyone with this issue call Apple support, and ask for assistance from senior level support to submit a problem to engineering. Also, submit a feedback request here: http://www.apple.com/feedback
    Ask to title your request "Keytone sound during call".
    Last, make sure when you call Apple you are ready to run through the diagnostics they will want you to do.
    That is:
    1. Back up your phone first either through iTunes or iCloud.
    2. Restore your Phone.
    3. If you are on iOS7, make sure it's the latest version.
    -- If you are on iOS6, the last version at this time is iOS 6.1.4
    4. Be prepared to do that either prior to the call or during.
    5. Ask for your case to be submitted to Engineering and to have a call back to resolve.
    Hopefully if we all band together, they will find the issue and we can get our hearing back after the numbing keytone has been blasted in our ears enough times.
    Please share your expierences here, but also note that other threads exist on this forum as well for the exact same problem!!
    And many more!
    ... And on almost ALL the carrier forums for support as well. If we all ask for help, and not just complain here, we should get a meaningful response and hopefully a fix!  Post up here when your case is in with Apple support.

  • Is there any way to ban Winsock Packet Editor from workin on your browser other players are using this progarm to interfer with peopels game play using your web browser on forfox

    ok i play yoville and people are using your web browser for the program Winsock Packet Editor Pro and everytime I try to enjoy yoville by zynga some fool uses your web browser to make winsock packet aditor to disconnect my player im so sick of this crap i work all day i exspect to come on yo and enjoy my game play not for some fool to use your web browser to make a program work and disconnect my player by gaining access to cdata people can also use wpe to get into others account with out any password or user name so is there any way to stop this program from working on your browser to stop these hackers from compromising accounts and ruining the fun of zynga games Ty for your kind Support and i hope u can help stop this program from working on your browser and from other browsers game play would be better off for all

    If you are meaning [http://wpepro.net http://wpepro.net], that tool doesn't use Firefox in the slightest. It uses TCP/IP (part of Windows) to Monitor networks (it can also be used nefariously).
    Please update your Firefox to Firefox 11, as the version you are running Is vulnerable to Many known security holes. After you do that, try to see if your problem is still going on.

  • Problem with generating a stub for a Web Service

    I have written a WebService in Delphi that I wan't to call from Java using JDeveloper 9i Release 2. The Web-service works since I can call the webservice from Delphi but the generated java stub just looks like this:
    public class ITempConverterserviceStub
    public String endpoint = "";
    private OracleSOAPHTTPConnection m_httpConnection = null;
    public ITempConverterserviceStub()
    m_httpConnection = new OracleSOAPHTTPConnection();
    m_httpConnection.
    I would expect some method declarations for the methods I want to call in my Webservice ?
    Regards
    Roger Gilliar

    Hi
    As told by Khaja, when generating DS for ODS the technical name will appear as  prefix 8 with ODS technical name.
    Check in DS's.
    If you using BI7, then you have to change into BD1 client, then only you can able to view your DS.
    Reg
    Pra

  • D Link 120 Bluetooth adaptor Interferes with the network preferences for BT

    Hi
    I just purchased a D Link 120 Bluetooth adaptor adaptor for my G4 machine running OSX10.4.10.
    When I connect it to a usb port, it works just fine and can see my mobile phone transfer files etc. The real problems begin when I restart my machine. On initial start up I cannot connect to the internet and in the network pane of the system preferences, I get a message saying a new port has been detected called Built in Ethernet-1
    When i click apply changes, the computer once more connects to the internet, however the name under which it connects is now saying Ethernet Adaptor ((null)). In short, is there a method to prevent the Bluetooth adaptor from interfering with my settings to connect to the internet?
    Thanks
    Jon

    Dear Justin,
    Did you end up getting this router? If so how have you found it?
    Thanks,
    Scot.

  • Calling an SWF with variables

    Is there a way to call an swf with variables, like we do
    dynamic web pages? Like this example:
    somedomain.com/some.swf?var1=whatever&var2=somethingelse
    I am trying to make a starting point for about 30 swfs and
    wanted a single logo starter for them all without having to include
    it in all the rest of the files. I wanted to call it, with 2
    variables, one just plain text to be displayed at the bottom right
    above a button, and the other was the filename of the next swf to
    load. I am doing this in a learning environment and the logo intro
    was to be used for all the lessons.
    Thanks.

    Hallo everyone,
    Since my initial posting, I have made good progress and have managed to split out my scripts so that one master-script calls the others passing various parameters. That's a great help.
    However, I have now come up against a problem which I am finding difficult to solve:
    In my main script I need to calculate the dates for each calling of the sub-scripts. I have experimented and have come up with several variations of date formatting. For example:
    TO_DATE('01.' || TO_CHAR(ADD_MONTHS(SYSDATE,-1), 'MM.YYYY'))
    I have tested the date formatting in a little test table to prove that the process runs correctly (i.e. valid dates are produced) and now I would like to move this syntax to my SQL*PLUS scripts to pass the dates as parameters to my other scripts.
    First I tried:
    PARAMETER xStartDate = TO_DATE('01.' || TO_CHAR(ADD_MONTHS(SYSDATE,-1), 'MM.YYYY'))
    &xStartDate
    ... but this didn't work as the processor interpreted the literal string.
    Next I tried:
    VARIABLE xStartDate1 DATE
    BEGIN
    :xStartDate1:=TO_DATE('01.' || TO_CHAR(ADD_MONTHS(SYSDATE,-1), 'MM.YYYY'))
    END
    :xStartDate
    ... but here too the literal value was passed.
    Can anyone help me with this? I need to set and change parameters/variables as my SQL*PLUS script is executed and then send these to other scripts.
    Or maybe I should first write the values (in this case Start- and End- Dates) to a table and then read the table and use the retrieved values to pass as arguments to the other scripts? Is this possible? Can it be done easily?
    Or maybe SQL*PLUS isn't designed for this (i.e. dynamic variables) and I should instead be using PL/SQL?
    I hope this isn't another false alarm (I don't believe it is) and am sure that you guys will be able to point me in the right direction.
    Many thanks,
    Alan Searle.
    Message was edited by:
    Alan____alse

  • Need help with how to call VB proceedure to open Adobe reader pdf file from differnt folders

    Using  MS access 9.0.2720  visual basic proceedure to call Adobe reader to open a specific flle from a folder on my c drive.
    useing the shell command , shellexecute is not available in the version I'm using.
    I can call the Reader with this code:   call shell "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"  and it will open reader, but
    I can't seem to get it to open a specific PDF file, I tried
    call shell "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" & "(folderpath)\.95.pdf"
    This use to work when I was running Xp and acrobat 5.0 , I am currentlt running windows 7
    thanks in advance..

    I am getting the exact error trying to down load bank statements but when I go to 'uncheck' the "Do not save encrypted page to disk" box it is ALREADY unchecked.  Can't get my bank statements down loaded.  Any other suggestions.  Need help quick.

  • How to call standard report with in zprogram?

    Hi Sap experts,
    How to call standard report with in zprogram.
    For example if country is 'US' then call Zprogram(zprog_US).Inside zprogram call standard report(rhecm_change_proc_status).If country is 'CA' then call zprogram.Inside zprogram call standard report.For same othercountres like 'PR','GB','ES'.Actually HR_ECM_READ_FEATURE_CARGP will having the input as employee id and will return the CAREA(County like 'US','PR'......).Kindly help me what is the procedure?
    Regards,
    Sujan

    >
    sujan T wrote:
    > Thanks for your reply.
    >
    >    What is the logic to call the standard report from zprogram?Inside the zpogram how to call standard report?
    >
    > Regards,
    > Sujan
    no special logic is required
    If u want to use
    RPUAUDOO IN THE ZREPORT.
    Put the submit button where ever required
    ex: In zreport after certain process reacedu want to call then use
    submit rpuaudoo and return.
    Regards
    Sas

  • Are the apple stores really open on Easter?

    Are the apple stores really open on Easter?
    On the store web page it says:
    April 04, 2010:
    10:00 a.m. - 7:00 p.m.
    Apple is not giving their employees Easter off?

    What's a day off? People get those?
    Some Apple Retail Stores are open, some are closed. For example:
    http://www.apple.com/retail/thesummit/
    I recommend checking http://www.apple.com/retail/storelist/ for Easter hours before heading to a particular store.

  • Whats wrong with the Network?

    What is wrong with the network? for about two days now i havent had 3g or 4g on my phone (droid razr maxx) just out of the blue it goes off my phone and hasnt come back. Does anyone know what happend?

        Yorktown301, that's very strange, but I'm here to figure this out! Are you still having problems connecting to 3G or 4G? Let's first verify that no settings on the phone were changed. Go to Settings, More, Mobile networks, Network Mode. Ensure LTE/CDMA is selected. Go back to Settings, Data usage and make sure Mobile Data is on. If still no change, remove both your battery and SIM card for about 30 seconds. If you're still having problems, let me know what zip code you're located in.
    MarquiaF_VZW
    Follow us on Twitter @VZWSupport

  • Help with Proper DNS Setup for Leopard Standard Server Setup

    Hello All,
    Problem Description-
    I was reviewing some training today on DNS setup and checking for proper setup with the sudo changeip - checkhostname tool and I seem to have an incorrectly configured DNS setup. So I need some help on correcting it. When I go to the "Server Preferences" tool I cannot log in using apple.ourdomainname.com instead in order to use the tool I have to input localhost as the server name. Now I just thought that the system was broken or something and with the help of my training I now see it's a DNS problem. I thought I had everything proper since I followed the steps of creating proper DNS/RDNS entries with my ISP. Now I am stuck wondering what else isn't working properly due to the DNS issue. Thanks in advance.
    Technical Info-
    My ISP provides us with 5 static IP's and we have asked them to create entries and verified the setup of apple.ourdomainname.com = x.x.x.x which is one of our public IP's assigned currently assigned to the WAN port of our Apple Airport Extreme. We have also had them create a PTR record which also is present, verified and functional. Our MacMini running 10.5.5 is connected directly to one of the ethernet ports on our Apple Airport Extreme which is our NAT/Firewall for the LAN. So during the setup of the Standard Server install the OS configured the Airport with the required ports for chat/web/vpn. And mobile Mac's can VPN in and gain folder access and web works fine too. We don't use the e-mail portion so I can't say how that works. The server is using the DNS of 10.0.200.1 which is the IP of the Airport and the airport is programmed with the DNS of OpenDNS servers 208.67.222.222 and 208.67.220.220. The reason for this whole long shpeal is that I want to give as much technical background as possible for the best possible help.
    Thanks
    DM

    What happens when you use 'Localhost' instead of 'localhost' (i.e. capitalizing the 'L')?

  • I got problem with volume of calls...its on max and i still can hear person on other side really bad...i got 4s

    i got problem with volume of calls...its on max and i still can hear person on other side really bad...i got 4s

    Did you fix the problem? I have the same problem and it has been pain in the neck.

Maybe you are looking for