I also have problems at times with latency using my Scarlett AI when I play my midi keyboard through the DAW.
You can fiddle with buffers and all that (search the forum for latency to find about a million suggestions). While this helps, for me it was not a 100% solution. You can also try the PDC button (Plugin Delay Compensation), which for me helped the latency, but seemed to mess up the timing of my tracks on playback.
Something I DO want to try, though, is based on what I read recently on the forum about how some effects will cause latency...this is all I know, and I planned on researching some more, but it sounded promising.
I do not play real-time along with my projects through the DAW all that often, so this has not been a huge issue for me...but it is annoying.