Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6244355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:18:42+00:00 2026-05-24T12:18:42+00:00

Disclaimer: The author is a newbie in OTP having some basic knowledge of Erlang’s

  • 0

Disclaimer: The author is a newbie in OTP having some basic knowledge of Erlang’s syntax, processes and messages.

I am trying to grasp the notion of behaviours in Erlang, but a lot of questions spring in my head preventing me from understanding the whole principle of such a behaviour like gen_server.

Okay, the official documentation for gen_server shows a nice diagram of a server and three clients connected with Query and Reply arrows:
http://www.erlang.org/doc/design_principles/gen_server_concepts.html

But each time I try to understand the concept further, I get stuck.

There is a lot of concepts which I cannot build into one larger concept in my head:

  • behaviour implementation;
  • behaviour container;
  • behaviour interface;
  • callback module;
  • callback functions;
  • API functions.

I use the following resources:

  • Erlang/OTP in Action book;
  • Introduction to OTP behaviours presentation, http://www.slideshare.net/gamlidek/ceug-introduction-to-otp-behaviors-part-i-genserver;
  • ‘ErlyBank’ at http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/index.html.

I am still in the state “we call one function in one module, this function calls the other function, that function creates a process… stuck”

Is there any way to describe the notion of gen_server in a diagram? How can an interaction flow between clients and a server be shown visually? (to help a not so smart newcomer to understand the concept visually)

For example like here: http://support.novell.com/techcenter/articles/img/dnd2003080506.gif

UPD: I have tried to draw a diagram of my own, but I still don’t get the purpose of any connector in the diagram: http://postimage.org/image/qe215ric/full/

UPD2: This is something similar to what I would like to see: http://cryptoanarchy.org/wiki/Worker_patterns (The Model). However, it doesn’t show the interaction between modules, functions and processes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:18:43+00:00Added an answer on May 24, 2026 at 12:18 pm

    I don’t have a precise drawing to explain it, but I have this chapter and the one after showing how to build gen_server starting with the abstraction principles behind it.

    To help with the individual components:

    behaviour implementation

    The behaviour itself is a bit like what is shown in the chapter I linked before. It’s a module with a bunch of functions doing all the generic stuff for you: receiving messages, defining functions and hidden protocols to communicate, etc. Advanced OTP stuff contains special kinds of messages used to do software upgrades and also special code for tracing options.

    behaviour container

    I’m not sure what this is supposed to be. Maybe just the module with the name of the behaviour?

    behaviour interface

    In the same module your behaviour implementation is, you have to define a behaviour_info/1 function. That function will let the Erlang compiler know that some callbacks are expected from any module that has -behaviour(SomeModuleName) in it. The SomeModuleName is equivalent to a SomeModuleName.erl (and .beam) file that contains the implementation and the behaviour_info function.

    callback module

    The module that will contain all the specific code, handling all the custom stuff.

    callback functions

    Everything that isn’t generic gets to be delegated to the callback module in the form of YourModule:SomeCall(Args). These are provided by your module, the one that has the -behaviour(gen_server). line in it.

    API functions

    The callback module has two interfaces, if you want: the one for the gen_server behaviour (init/0, handle_call/3, handle_info/2, handle_cast/2, terminate/2, code_change/3), and the one for the user (start the server, send some information, ask for some information back).

    I could try to describe it that way

    ---------------------------------------------------------------------
    | some process          |                server process             |
    ------------------------+--------------------------------------------
       [client]             |      [callback]     :        [behaviour]
                            |                     :
     callback:start >-------|---------------------:--> starting the process
                            |                     :           V
                            |                     :           |
                            |       init()  <-----:-----------`
                            |         |           :
                            |         `-----------:------> initial state
      {ok, Pid}  <----------|---------------------:----------,/
                            |                     :
     callback:store  >------|---------------------:--> handles message
     (calls the process)    |    (formats msg)    :           V
                            |                     :           |
                            |    handle_call() <--:-----------` 
                            |         |           :
                            |          `----------:--> updates state, sends reply
                            |                     :        V
                            |                     :        |
       gets result <--------|---------------------:--------`
                            |                     :       
    

    All the generic parts are on the right of the server process, within the behaviour, and all the specific parts are on the left (callback). The client uses the callback module’s API/interface to contact the server process and have effects on it.

    You have to see the behaviour as some kind of very generic code segment that sometimes gives up its execution flow (for more precise parts, like receiving and sending messages) to the specific code (how to react to these messages).

    Hopefully this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: the following is a sin against XML. That's why I'm trying to change
Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer: I'm stuck on TFS and I hate it. My source control structure looks
Disclaimer: I'm fairly new to python! If I want all the lines of a
Disclaimer Yes, I am fully aware that what I am asking about is totally
Disclaimer: This is for a homework assignment, but the question is not regarding the
DISCLAIMER: The following code is not something I would ever use in a real
Disclaimer This is not strictly a programming question, but most programmers soon or later
Full disclaimer: I'm a CS student, and this question is related to a recently
I'm relatively(read: stupid newbie) familiar with disassembly but this bit stumped me: I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.