Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Enhancing Network Communication in Android: Tra...

Enhancing Network Communication in Android: Transitioning from REST to GraphQL

In this presentation, we will explore different approaches for network communication in Android, starting with traditional RESTful APIs and progressing to GraphQL. We will discuss the pros and cons of each approach and provide practical guidance on implementing efficient and scalable network layers in Android apps. Through examples and real-world scenarios, you will gain insights into selecting the right approach for your app's specific needs.

Avatar for kemal selim tekinarslan

kemal selim tekinarslan

October 26, 2023
Tweet

Other Decks in Technology

Transcript

  1. Who am I? Kemal Selim Tekinarslan Sr. Android Engineer Kotlin

    & Android. Travel Lover Paragliding is passion Links: /tekinarslan on Github /in/tekinarslan/ on LinkedIn
  2. About HolidayPirates The HolidayPirates Group is one of the fastest-growing,

    free-to-use, travel search platforms and apps, providing users with the best value for money travel deals.
  3. 01 The Importance of Efficient Network Communication 02 REST API

    Overview 03 Introducing GraphQL 04 Challenges with REST 05 Why adopt GraphQL? Contents An overview of what I will present to you today
  4. Efficient Network Communication Battery Life Efficient network communication preserves device

    battery by minimizing data transmission, boosting the application's energy efficiency
  5. Efficient Network Communication Scalability When network communication is optimized, applications

    improve scalability and performance, efficiently managing a higher user and data request load.
  6. Efficient Network Communication Bandwidth Optimization Simplified communication optimizes network bandwidth

    usage, ensuring efficient data transfers while minimizing resource consumption.
  7. Efficient Network Communication Support for Low-Connectivity Environments Optimized communication is

    crucial for users in areas with limited connectivity, enabling applications to function more reliably and provide essential services even under challenging network conditions.
  8. Efficient Network Communication Improved User Experience Optimizing network communication ensures

    a seamless user experience with swift interactions and data loading, enhancing overall app enjoyment.
  9. REST, which stands for Representational State Transfer, is an architectural

    style for designing networked applications. It was introduced by Roy Fielding in his doctoral dissertation in 2000 REST and its key concepts
  10. REST and its key concepts Uniform Interface RESTful services should

    have a uniform and consistent interface. This means that resources should be accessible through a consistent set of URLs and use standard HTTP methods.
  11. REST and its key concepts Methods GET: Retrieve data from

    the server. POST: Create new resources on the server. PUT: Update existing resources on the server. DELETE: Delete resources on the server.
  12. REST and its key concepts Stateless Communication REST is designed

    to be stateless, meaning that each request from a client to the server must contain all the necessary information to understand and fulfill the request. Servers do not store any client state between requests.
  13. REST and its key concepts Scalability and Performance REST's statelessness

    and caching mechanisms contribute to improved scalability and performance of APIs, as resources can be distributed and cached effectively.
  14. GraphQL and its key concepts Types Scalar : Basic atomic

    types like Int, Float, String, Boolean, and ID. Object : Custom defined types that represent real-world objects like users, posts, comments, etc. Enum : A set of predefined values, like statuses, that a field can have. Input : Used in mutations to pass complex input data.
  15. GraphQL and its key concepts Schema GraphQL starts with defining

    a schema that outlines the types of data that can be queried and the relationships between them. The schema is the contract between the client and the server, specifying what types of queries and mutations are available.
  16. Queries Queries request data from servers, shaped by the client's

    needs, specifying desired fields and any filtering or sorting arguments. GraphQL and its key concepts
  17. Mutations Mutations are similar to queries, but they are used

    to modify data on the server. They can perform actions like creating, updating, or deleting data. GraphQL and its key concepts
  18. How GraphQL Overfetching and Underfetching: When using REST APIs, it's

    possible to receive more data than needed (overfetching) or not enough data (underfetching). This can impact performance and user experience. solves the challenges faced by REST
  19. Overfetching and Underfetching: When using REST APIs, it's possible to

    receive more data than needed (overfetching) or not enough data (underfetching). This can impact performance and user experience. Overfetching and Underfetching GraphQL addresses overfetching and underfetching problems by enabling clients to request precisely tailored data, optimizing data retrieval through a specified response structure in the query language. How GraphQL solves the challenges faced by REST
  20. Multiple Requests REST APIs often require multiple endpoints to retrieve

    different types of data, resulting in a multiplication of endpoints and increased complexity. How GraphQL solves the challenges faced by REST
  21. Multiple Requests REST APIs often require multiple endpoints to retrieve

    different types of data, leading to a proliferation of endpoints and increased complexity. Multiple Requests GraphQL streamlines the API architecture by consolidating all queries into a single endpoint, minimizing the number of endpoints and simplifying network requests for clients. How GraphQL solves the challenges faced by REST
  22. N+1 Query Problem In REST, fetching related data often requires

    multiple requests, leading to the N+1 query problem, where one initial request is followed by N additional requests to retrieve associated data. How GraphQL solves the challenges faced by REST
  23. N+1 Query Problem In REST, fetching related data often requires

    multiple requests, leading to the N+1 query problem, where one initial request is followed by N additional requests to retrieve associated data. N+1 Query Problem GraphQL efficiently resolves this issue using 'resolver functions' that fetch data for each query field, enabling developers to optimize and batch data retrieval. How GraphQL solves the challenges faced by REST
  24. Data Loading When you request data from a single REST

    endpoint, you usually receive the full dataset associated with that endpoint. In this case application screen will not load at low internet speeds. How GraphQL solves the challenges faced by REST
  25. Data Loading When you request data from a single REST

    endpoint, you usually receive the full dataset associated with that endpoint. In this case application screen will not load at low internet speeds. Data Loading GraphQL empowers clients to perform partial data loading during the fetching process. How GraphQL solves the challenges faced by REST
  26. Versioning REST APIs often require versioning to maintain backward compatibility,

    and changes to the API can result in breaking changes for clients. How GraphQL solves the challenges faced by REST
  27. Versioning REST APIs often require versioning to maintain backward compatibility,

    and changes to the API can result in breaking changes for clients. Versioning GraphQL's strong type system and versionless schema make it easier to evolve APIs without introducing breaking changes. Clients can request the exact shape of data they expect. How GraphQL solves the challenges faced by REST
  28. GraphQL is production-ready GraphQL is tried, tested, and proven to

    be stable for use in real-world applications. Its wide adoption by major companies attests to its readiness and reliability in production environments. GraphQL? Why adopt
  29. Frontend Control over Data GraphQL empowers the client to request

    specific data fields, granting fine- grained control and reducing unnecessary data transmission. GraphQL? Why adopt
  30. Real-time Capabilities GraphQL enables dynamic and interactive user experiences by

    supporting real-time updates through subscriptions. GraphQL? Why adopt
  31. Federated Architecture GraphQL's federated approach enhances scalability and autonomy by

    enabling services to own and manage designated parts of the schema. GraphQL? Why adopt
  32. Versioning and Evolution GraphQL provides a backward-compatible approach to schema

    changes, enabling smooth versioning and evolution of APIs without breaking existing clients. GraphQL? Why adopt
  33. Single Endpoint, Multiple Sources GraphQL consolidates multiple data sources into

    a single endpoint, streamlining data retrieval and minimizing round-trip requests. GraphQL? Why adopt
  34. Parallel Data Loading GraphQL allows for parallel data loading, enhancing

    performance by fetching related data concurrently. GraphQL? Why adopt
  35. Strongly Typed Schema A Strongly Typed Schema in GraphQL enforces

    a defined structure for data queries, specifying the types and relationships allowed, ensuring consistency and predictability in data retrieval. GraphQL? Why adopt
  36. Efficient Development Workflow 1 Self-Documenting APIs 2 Versionless Evolution 4

    Collaboration and Frontend Independence 3 The schema is a powerful source of truth. 5 Elevating Developer Experience GraphQL? Why adopt
  37. Additional data per session = 2KB Total additional data consumption

    = Additional data per session * Total number of sessions Total number of sessions = Active users (1 million) * Total number of sessions (5 times a day) Total number of sessions = 100,000,000 sessions Total additional data consumption = Additional data per session * Total number of sessions Total additional data consumption = 5KB * 100,000,000 sessions Total additional data consumption = 500,000,000 KB 500,000,000 KB ÷ 1,024 (KB in a MB) ÷ 1,024 (MB in a GB) ≈ 500 GB Network Traffic.