May be one of 4 things, and I have experienced them.
1) Your 3ds~ sometimes, my 3ds has had glitches causing lag. this is from it coming to my connection part of my 3ds. This can be fixed by resetting, and is rare for newer consoles in my perspective.
2) Opponent~ It may not be you or your opponent's 3ds, but it could be their internet. best to fix this is to leave game AFTER MATCH. or else you need to wait 10 min to play again.
3) Your internet~ Good ways to know it is your internet is determining how long something takes, like a download. I recently got new internet, and it is better. (A gamecube ISO from taking 8 hours to 3). Just look for the file size, the time it takes, and how long it should normally be. Don't just get completely new internet unless you know. One way to fix this is to reset the internet box. unplug for 12 seconds, then plug back in and wait.
4) Nintendo's Servers~ I read an article once showing that Nintendo did not really know how to make good online play like the Xbox and Play Station, so they are trying. Sometimes, it is on nintendo for the lag. like my friend has perfect wifi, and i am under my good wifi, yet we sometimes lag. To deal with this, wait for about 10 min. get a coffee break.